
#include "Channels.h"
#include "ChannelManager.h"
#include "Resource.h"
#include "String.h"
#include "SharedPtr.h"
#include "ResourceManager.h"
#include "Database/DatabaseEnv.h"
#include "StringConverter.h"
#include "NGLog.h"
#include "Character.h"
#include "CharManager.h"
#include "Items.h"
#include "ItemManager.h"
#include "WorldPacket.h"
#include "Towns.h"
#include "Effects.h"
#include "EffectManager.h"
#include "EffectModels.h"
#include "EffectModelManager.h"
#include "Users.h"
#include "UserManager.h"
#include "XMLData.h"
#include "Towns.h"
#include "Message.h"
#include "XMLData.h"
#include "OpcodesEx.h"
#include "VipCardManager.h"
#include "Tools.h"
#include "WSSocket.h"
#include "AIScript.h"

#include "TWMJOpcode.h"
#include "TWMJAIInterface.h"
#include "TWMJGameStruct.h"
#include "TWMJXmlDataManager.h"
#include "TWMJGameThreadLogic.h"
#include "TWMJProtocolsManager.h"
#include "TWMJGameLogicManager.h"
#include "LogDataManager.h"
#include "MJGameLogic.h"

namespace AIScript {

	//构造函数
	TWMJAIChannelInterface::TWMJAIChannelInterface(Resource * pUnit) : AIMaJiangChannelBaseInterface(pUnit)
	{
		m_AIType = AITYPE_WCHANNEL;
	}
	//析构
	TWMJAIChannelInterface::~TWMJAIChannelInterface()
	{
	}

	uint32 TWMJAIChannelInterface::GetMaxPlayerNum()
	{
		return m_nMaxPlayerNum;
	}

	// load
	void TWMJAIChannelInterface::Load()
	{	
		//加载配置
		//LoadTWMJXml();

		Log.Debug("TWMJAIChannelInterface::Load", "Load........");
		AIMaJiangChannelBaseInterface::Load();
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			TWMJTablePlayers *pTp = TO_TWMJTP(GetTablePlayerByPos(i));
			if (pTp)
			{
				pTp->init(true);
			}
		}
		initCenterBattleInfo();

		//((TWMJGameLogic *)m_GameLogic)->FuncInit(m_bLiGuLiGu);
		//m_AddTaiTypeGroup = ((TWMJGameLogic *)m_GameLogic)->GetTaiType();
		int robot_num = sXmlDataMgr.getTWMJconf("ROBOT_NUM");
		for (int i = 0; i < robot_num; ++i)
		{
			CharPtr chr;
			Resource * pChar = sCharMgr.newDumyChar();

			if (!pChar)
			{
				Log.Debug("23", "1");
				continue;
			}
			Vector3 pos = sRegionMgr.getWorldRondomPosition();
			pChar->setFloatField("x", pos.x);
			pChar->setFloatField("y", pos.y);
			pChar->setUInt32Field("id", RandomUInt(511, 513));
			uint32 number = (RandomUInt(10032, 20001));
			String name = "御坂" + StringConverter::toString(number);
			if (number == 20001)
				name = "最后之作";
			if (!StringUtil::checkStringUTF8(name))
				name = StringUtil::StringToUTF8(name);
			pChar->setStringField("name", name);
			pChar->setUInt32Field("lv", 1);
			pChar->setUInt32Field("exps", 0);
			pChar->setUInt32Field("status", CharacterStatusFree);
			pChar->setUInt32Field("create_time", time(0));
			pChar->setUInt32Field("isnpc", 2);
			pChar->setUInt32Field("motion", i);															//总场次
			pChar->setUInt32Field("payment", 0);														//胜场
			pChar->setUInt32Field("attribute", 0);														//跪场
			pChar->setUInt32Field("ability", 0);														//胜率
			pChar->setUInt32Field("defence_ext", 0);													//击坠
			pChar->setUInt32Field("attack_ext", 0);														//勋章
			pChar->setUInt32Field("hp", 1);																//勋章等级
			pChar->setUInt32Field("protect", 1);														//经验
			pChar->setUInt32Field("max_hp", 0);															//遥控骰子	
			pChar->setUInt32Field("speed", 500000);
			pChar->setStringField("desc", "http://192.168.0.165/gwmember/kefu/128x128.png");
	//		pChar->setStringField("desc", "	file://192.168.0.173/zm/a.png");
	
			chr = sCharMgr.loadCharDatabase(pChar);
			sCharMgr.freeDumyChar(pChar);
			sGLMgr.CreateItem(chr, ItemModel_Coins, 500000);
			// PHZAICreatureInterface* aiChrInter = TO_PHZCREATURE_INTERFACE(chr->getAIInterface());

			// if(aiChrInter)
			// {
			// aiChrInter->chr_state = PHZAICreatureInterface::ready;
			// }
			JoinChannel(chr);

			//	sGLMgr.robotList.push_back(chr);

		}
		m_ui8LastBankerPos = INVALID_uint8;
		m_OldPlayerId.clear();
		m_i8SwapCardsPosType = enMJSwapCardsPosType_Random;
	}
	void TWMJAIChannelInterface::InitGameLogic()
	{
		m_GameLogic = ::TWMJGameLogic::Create(m_Unit->getUInt32Field("ai"), m_AddTaiTypeGroup, m_bLiGuLiGu);

		if (m_GameLogic == NULL)
		{
			Log.Error("TWMJAIChannelInterface::InitGameLogic", "Create m_GameLogic FAILED ai:%d", m_Unit->getUInt32Field("ai"));
			ASSERT(false);
		}
	}
	void TWMJAIChannelInterface::initialize()
	{

		AIMaJiangChannelBaseInterface::initialize();
		m_ui8PONum = 0;
		//玩家手牌列表   索引值
		std::vector<uint8> m_ui8VecUserCardIndexTemp(MAX_INDEX, 0);
		VecInit<std::vector<uint8> >(m_ui8First4Cards, m_nMaxPlayerNum, m_ui8VecUserCardIndexTemp);
		VecInit<bool>(nIsRealHuPai, m_nMaxPlayerNum, false);
		m_SendCardsTimes = 0;
	//	m_nIsRealHuPai = 0;

		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			TWMJTablePlayers * pTp = TO_TWMJTP(GetTablePlayerByPos(i));
			if (pTp)
			{
				pTp->init(false);
			}
		}
		Log.Debug("TWMJAIChannelInterface::initialize", "m_uin8AddCardTai clear!");
		//加番列表
		VecInit<std::vector<uint8> >(m_uin8AddCardTai, m_nMaxPlayerNum, std::vector<uint8>());
		//m_ui8PayMode = 2;
		PlayerCalc.clear();
		SelfMomentMaPaiList.clear();
		PlayerGangShangPao.clear();
		IsPlayerZhuanYu.clear();
		for(uint8 i = 0; i < 4; ++i)
		{
			PlayerCalc.push_back(0);
			PlayerGangShangPao.push_back(0);
			IsPlayerZhuanYu.push_back(0);
		}
	}
	void TWMJAIChannelInterface::initCenterBattleInfo(void)
	{
		AIMaJiangChannelBaseInterface::initCenterBattleInfo();

		m_GameLogic->LogDeBug("TWMJAIChannelInterface::initCenterBattleInfo", "initCenterBattleInfo");
		Json::Reader reader;
		Json::Value val;
		reader.parse(m_Unit->getStringField("info"), val);
		if (val.isMember("extra_data"))
		{
			Json::Value val2 = val["extra_data"];
			if (val2.isMember("playerSum"))
			{ // 最大玩家数量
				m_nMaxPlayerNum = val2["playerSum"].asUInt();
			}

			if (val2.isMember("out_time"))
			{ // 出牌间隔
				m_nTimeInterval = val2["out_time"].asUInt();
				m_nCastHandCardTime = m_nTimeInterval * 1000;
			}
			if (val2.isMember("tai_num"))
			{ // 台分
				m_nTaiScore = val2["tai_num"].asUInt();
			}

			/*******************可勾选玩法************************/

			if (val2.isMember("isLGLG"))
			{ // 呖咕呖咕
				m_bLiGuLiGu = val2["isLGLG"].asUInt();
			}
			if (val2.isMember("isQQY"))
			{ // 七抢一
				m_bQiQiangYi = val2["isQQY"].asUInt();
			}
			if (val2.isMember("isZMCNH"))
			{ // 自摸才能胡
				m_bOnlyZiMoHu = val2["isZMCNH"].asUInt();
			}
			if (val2.isMember("isBTCNH"))
			{ // 报听才能胡
				m_bOnlyBaoTingHu = val2["isBTCNH"].asUInt();
			}
			if (val2.isMember("isBDGS"))
			{ // 不得过水
				m_bNotAllowGuoShui = val2["isBDGS"].asUInt();
			}
			if (val2.isMember("isBTYT"))
			{ // 报听有台
				m_bBaoTingHaveTai = val2["isBTYT"].asUInt();
			}
			if (val2.isMember("isTTDT"))
			{ // 天听地听
				m_bTianAndDiTing = val2["isTTDT"].asUInt();
			}
		}
	}

	void TWMJAIChannelInterface::Update(const uint32 & p_time)
	{
		AIMaJiangChannelBaseInterface::Update(p_time);
	}

	//===========接口相关==================

	//初始话玩家列表
	void TWMJAIChannelInterface::InitPlayerSeatList()
	{
		// 初始座位列表
		for (uint8 i = 0; i < m_nMaxPlayerNum; ++i)
		{
			MJBaseTablePlayer* tp = new TWMJTablePlayers;

			//重要   从tableplayer获取手牌数据必须调用该方法
			tp->SetChannelInterface(this);

			tp->playerJoinState = MJ_PlayerReadyStatus_Join;
			tp->pos = i;
			m_vSeatPlayers.push_back(tp);
		}
	}

	/************************延时状态**************************/
	// void TWMJAIChannelInterface::setChannelBattleDelay(void)
	// {
	// 	WGS_MJCHANNEL_LOCK;
	// 	if (m_bVoting)
	// 		return;
	// 	m_status_endtimer = now() + sXmlDataMgr.GetConfXMLValue("D_Time1");
	// 	m_next_run_status = en_MJChannelState_ChooseBanker;
	// }
	// HSMState TWMJAIChannelInterface::battle_Delay(TWMJAIChannelInterface *me, HSMEvent const *e)
	// {
	// 	switch (e->sig)
	// 	{
	// 	case HSM_INIT_SIG:
	// 		me->setRunStatus(en_MJChannelState_Custom);
	// 		me->setChannelBattleDelay();
	// 		return HSM_HANDLED();
	// 	case HSM_UPDATE_SIG:
	// 		VCALL(en_MJChannelState_Custom)
	// 		return HSM_HANDLED();
	// 	}

	// 	return HSM_SUPER(&Hsm::hsm_top);
	// }

	// HSMStateHandler TWMJAIChannelInterface::ChannelBattleDelayUpdate(void)
	// {
	// 	if (m_status_endtimer <= now())
	// 	{ // 延时时间到
	// 		return ChangeChannelState(m_next_run_status);
	// 	}

	// 	return 0;
	// }



	// 抓位、定庄Init
	void TWMJAIChannelInterface::setChannelBattleChooseBanker(void)
	{
		WGS_MJCHANNEL_LOCK;
		if (m_bVoting)
			return;
		WorldPacket packet;

		// 丢骰子
		for (uint8 i = 0; i < 4; i++)
		{
			m_dice[i] = RandomUInt(1, 6);
		}
	
		//第一局或者不是原来的四个玩家执行 抓位 掷骰子定庄
		if(!OldPlayerId())
		{	
			//初始化
			m_ui8BankerPos = INVALID_uint8;
			m_ui8NextBankerPos = INVALID_uint8;
			m_ui8DongFengSeat = INVALID_uint8;
			m_ui8LastBankerPos = INVALID_uint8;
			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				TWMJTablePlayers *pTp = TO_TWMJTP(GetTablePlayerByPos(i));
				if (pTp)
					pTp->init(true);
			}

			Log.Debug("TWMJAIChannelInterface::setChannelBattleChooseBanker", "第一局或重新开始游戏......");
			//抓位
			Alignment();
			Wait(5000);
			//随机生成庄家cd
			MakeRandBanker();
			//发送骰子数
			if (sProtocolsMgr.CreateBroadcastDiceResultPacket(&packet, m_dice))
				BroadcastPacket(&packet);
		}
		else
		{ //轮庄
			Log.Debug("TWMJAIChannelInterface::setChannelBattleChooseBanker", "开始下一局...... m_ui8BankerPos:%d ", m_ui8NextBankerPos);
			m_vSeatPlayers[m_ui8BankerPos]->isBanker = false;
			m_ui8BankerPos = m_ui8NextBankerPos;
			TWMJTablePlayers *pTp = TO_TWMJTP(GetTablePlayerByPos(m_ui8BankerPos));
			pTp->banker_count += 1;
			if(m_ui8LastBankerPos != m_ui8BankerPos)
				pTp->banker_count = 0;
			Log.Debug("TWMJAIChannelInterface::setChannelBattleChooseBanker", "m_ui8BankerPos:%d banker_count[%u]", m_ui8BankerPos, pTp->banker_count);
		}

		//配牌
		//TestHandCards();
		TWMJTablePlayers *pTp = TO_TWMJTP(GetTablePlayerByPos(m_ui8BankerPos));
		m_ui8CurrentPos = m_ui8BankerPos;
		m_vSeatPlayers[m_ui8BankerPos]->isBanker = true;
		//发送风圈信息
		if (sProtocolsMgr.CreateBroadCurrentWindPacket(&packet, m_nRoundId, pTp))
			BroadcastPacket(&packet);
		Wait(3000);
		//发送牌桌状态
		SendTableStatus(0);
		//发送连庄次数
		if (sProtocolsMgr.CreateBroadcastContinueBankerPacket(&packet, pTp))
			BroadcastPacket(&packet);
	
		m_status_endtimer = now() + m_nChooseBankerWaitTimer;
		m_next_run_status = en_MJChannelState_SendCards;

		LogGameStart();
		Log.Debug("TWMJAIChannelInterface::setChannelBattleChooseBanker", "channel[%u] cb_id[%u] m_ui8BankerPos:%d!", m_Unit->getHandle(), m_btLog.cb_id, m_ui8BankerPos);
	}
	//检测是否为原始玩家
	bool TWMJAIChannelInterface::OldPlayerId()
	{
		//第一局
		if(!m_OldPlayerId.size())
			return false;

		uint8 count = 0;
		for (uint8 i = 0; i < m_nMaxPlayerNum; ++i)
		{
			TWMJTablePlayers *pTp = TO_TWMJTP(GetTablePlayerByPos(i));
			if (pTp)
			{
				for (uint8 i = 0; i < m_OldPlayerId.size(); ++i)
				{
					if (pTp->player._handle == m_OldPlayerId[i])
					{
						++count;
						Log.Debug("TWMJAIChannelInterface::OldPlayerId", "玩家[%d]ID:%d", pTp->pos, pTp->player._handle);
					}

				}
			}
		}

		//不是全部原始玩家
		if(count != 4)
			return false;

		return true;
	}
	//抓位
	void TWMJAIChannelInterface::Alignment()
	{
		m_OldPlayerId.clear();
		WorldPacket packet;
		//随机玩家顺序进行抓牌
		std::vector<uint8> Alignment1, Alignment2;
		for (uint8 i = 0; i < m_nMaxPlayerNum; ++i)
		{
			Alignment1.push_back(i);
		}
		for (uint8 i = 0; i < m_nMaxPlayerNum; ++i)
		{
			uint8 n = RandomUInt(Alignment1.size() - 1);
			Alignment2.push_back(Alignment1[n]);
			TWMJTablePlayers *pTp = TO_TWMJTP(GetTablePlayerByPos(i));
			if (pTp)
			{
				m_OldPlayerId.push_back(pTp->player._handle);
				pTp->windPos = Alignment1[n];
				Log.Debug("TWMJAIChannelInterface::Alignment", "pos[%d]ID:%d i[%d] windpos[%d] 玩家昵称：%s ",
						  pTp->pos, pTp->player._handle, i, pTp->windPos, GetPlayerName(*pTp));
			}

			std::vector<uint8>::iterator iter = Alignment1.begin() + n;
			Alignment1.erase(iter);
		}

		for(uint8 i = 0; i < m_nMaxPlayerNum; ++i)
		{
			TWMJTablePlayers *pTp = GetTablePlayerWindPos(i);
			pTp->pos = pTp->windPos;
			if (pTp->windPos == 0 && m_ui8DongFengSeat == INVALID_uint8)
				m_ui8DongFengSeat = pTp->pos;
			Log.Debug("TWMJAIChannelInterface::Alignment", "pos[%d]ID:%d i[%d] windpos[%d] 玩家昵称：%s ",
					  pTp->pos, pTp->player._handle, i, pTp->windPos, GetPlayerName(*pTp));
		}

		//发送抓牌顺序
		if (sProtocolsMgr.CreateDrawOrderPacket(&packet, Alignment2))
			BroadcastPacket(&packet);
	}
	//通过风位获取玩家
	TWMJTablePlayers *TWMJAIChannelInterface::GetTablePlayerWindPos(const uint32 &Windpos_id)
	{
		TWMJTablePlayers *pTp = NULL;
		TablePlayerIter iter = m_vSeatPlayers.begin();
		for (; iter != m_vSeatPlayers.end(); ++iter)
		{
			if (!(*iter)->player.isNull() && TO_TWMJTP(*iter)->windPos == Windpos_id)
			{
				pTp = TO_TWMJTP(*iter);
				break;
			}
		}

		return pTp;
	}
	bool TWMJAIChannelInterface::IsEstimateHu(const uint8 &ui8CurrentPos, const uint8 &ui8EstimatePos, const uint8 &ui8CenterCard)
	{

		return (!m_bEnjoinChiHu[ui8CurrentPos] && OnlyAllowBaoTingHu(ui8CurrentPos));
	}
	//获取胡牌番型
	uint32 TWMJAIChannelInterface::GetHuPaiFanXing(const uint8 &ui8PlayerPosID) //玩家座位号
	{
		uint32 ui32Result = 0;
		CChiHuRight &chr = m_ChiHuRight[ui8PlayerPosID];
		if ((chr & en_HuPaiTaiType_DaSiXi).IsEmpty() == false)
		{ //大四喜
			ui32Result = enTaiType_DaSiXi;
		}
		else if ((chr & en_HuPaiTaiType_XiaoSiXi).IsEmpty() == false)
		{ //小四喜
			ui32Result = enTaiType_XiaoSiXi;
		}
		else if ((chr & en_HuPaiTaiType_WuAnKe).IsEmpty() == false)
		{ //五暗刻
			ui32Result = enTaiType_WuAnKe;
		}
		else if ((chr & en_HuPaiTaiType_ZiYiSe).IsEmpty() == false)
		{ //字一色
			ui32Result = enTaiType_ZiYiSe;
		}
		else if ((chr & en_HuPaiTaiType_QingYiSe).IsEmpty() == false && (chr & en_HuPaiTaiType_PingHu).IsEmpty() == false)
		{ //清一色
			ui32Result = enTaiType_QingYiSe;
		}
		else if ((chr & en_HuPaiTaiType_DaSanYuan).IsEmpty() == false)
		{ //大三元
			ui32Result = enTaiType_DaSanYuan;
		}
		else if ((chr & en_HuPaiTaiType_SiAnKe).IsEmpty() == false)
		{ //四暗刻
			ui32Result = enTaiType_SiAnKe;
		}
		else if ((chr & en_HuPaiTaiType_CouYiSe).IsEmpty() == false && (chr & en_HuPaiTaiType_PingHu).IsEmpty() == false)
		{ //凑一色
			ui32Result = enTaiType_HunYiSe;
		}
		else if ((chr & en_HuPaiTaiType_XiaoSanYuan).IsEmpty() == false)
		{ //小三元
			ui32Result = enTaiType_XiaoSanYuan;
		}
		else if ((chr & en_HuPaiTaiType_PengPengHu).IsEmpty() == false)
		{ //碰碰胡
			ui32Result = enTaiType_PengPengHu;
		}
		else if ((chr & en_HuPaiTaiType_SanAnKe).IsEmpty() == false)
		{ //三暗刻
			ui32Result = enTaiType_SanAnKe;
		}
		else if ((chr & en_HuPaiTaiType_PingHu).IsEmpty() == false)
		{ //平胡
			ui32Result = enTaiType_PingHu;
		}
		else if ((chr & en_HuPaiTaiType_LiGuLiGu).IsEmpty() == false)
		{ //呖咕呖咕
			ui32Result = enTaiType_LiGuLiGu;
		}

		return ui32Result;
	}
	//获取其他番型数
	uint32 TWMJAIChannelInterface::GetOtherTaiType(const uint8 &ui8PlayerPosID)
	{
		uint32 ui32Result = 0;
		uint32 ui32BuHuaNum = 0;									   //补牌
		uint32 ui32CommonNum = 0;									   //通用
		ui32CommonNum = m_uint8MaxCardNum - m_ui8MaxHandCount * 4 - 1; //最大牌数量 手牌数量 特殊
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			ui32BuHuaNum += m_ui8HuaPaiList[i].size();

		Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "----------ui32BuHuaNum[%d] ----------------", ui32BuHuaNum);
		CChiHuRight &chr = m_ChiHuRight[ui8PlayerPosID];
		TWMJTablePlayers *pTp = TO_TWMJTP(GetTablePlayerByPos(ui8PlayerPosID));
		if (pTp == NULL)
			return ui32Result;

		//摸到流局前的最后一张牌胡牌
		if (m_uint8LeftCardCount < 4 && m_ui8ProvidePos == ui8PlayerPosID)
		{ //海底捞
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "海底捞[%d]", enTaiType_HaiDiLao);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_HaiDiLao);
		}

		if (IsLingShangKaiHua())
		{ //杠上花
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "杠上花[%d]", enTaiType_GangShangKaiHua);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_GangShangKaiHua);
		}

		uint8 ui8PlayerOutCardCount = 0;
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			ui8PlayerOutCardCount += m_ui8DiscardCard[i].size();
		}
		uint8 ui8PlayerWeaveCount = 0;
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			ui8PlayerWeaveCount += m_WeaveItemArray[i].size();
		}

		//庄家特权
		if (ui8PlayerPosID == m_ui8BankerPos)
		{
			if (IsZiMo() && ui8PlayerOutCardCount == 0 && ui8PlayerWeaveCount == 0 
			&& (m_uint8LeftCardCount == (ui32CommonNum - ui32BuHuaNum)) && nIsRealHuPai[ui8PlayerPosID]) //减去花牌、发的牌、
			{	//天胡
				Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "天胡[%d]", enTaiType_TianHu);
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_TianHu);
			}
		}
		else
		{ //闲家
			uint8 firstpos;
			for (uint8 i = 1; i <= m_nMaxPlayerNum; i++)
			{
				uint8 poos = ((m_ui8BankerPos + i) % m_nMaxPlayerNum);
				if (poos == ui8PlayerPosID)
				{
					firstpos = i;
					break;
				}
			}
			uint8 ui8outcardnum = m_ui8DiscardCard[ui8PlayerPosID].size();
			if (IsZiMo() && ui8outcardnum == 1 && ui8PlayerWeaveCount == 0 
			&& (m_uint8LeftCardCount == (ui32CommonNum - ui32BuHuaNum - firstpos))&& nIsRealHuPai[ui8PlayerPosID])
			{ //地胡
				Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "地胡[%d]", enTaiType_DiHu);
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_DiHu);
			}
		}

		//人胡
		if (IsFangPao() && (m_uint8LeftCardCount >= (ui32CommonNum - ui32BuHuaNum - 4))
		 && ui8PlayerWeaveCount == 0 && nIsRealHuPai[ui8PlayerPosID])
		{
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "人胡[%d]", enTaiType_RenHu);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_RenHu);
		}

		if (m_bTianAndDiTing)
		{
			//天听（庄家）
			if (ui8PlayerPosID == m_ui8BankerPos)
			{
				if ((m_bBaoJiao[ui8PlayerPosID]) && m_uint8LeftCardCount == (ui32CommonNum - ui32BuHuaNum) && nIsRealHuPai[ui8PlayerPosID])
				{
					Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "天听（庄家）[%d]", enTaiType_TianTin);
					m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_TianTin);
				}
			}

			//地听
			if (ui8PlayerWeaveCount == 0 && ui8PlayerPosID != m_ui8BankerPos && (m_bBaoJiao[ui8PlayerPosID]) 
			&& (m_uint8LeftCardCount >= ui32CommonNum - ui32BuHuaNum - 4) && nIsRealHuPai[ui8PlayerPosID])
			{
				Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "地听[%d]", enTaiType_DiTing);
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_DiTing);
			}
		}

		//配牌花胡
		// if (m_ui8HuaPaiList[ui8PlayerPosID].size() == 8 && m_uint8LeftCardCount >= ui32BuHuaNum)
		// {
		// 	m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_PeiHuaHu);
		// }
		// else if (m_ui8HuaPaiList[ui8PlayerPosID].size() == 7 && m_uint8LeftCardCount >= ui32BuHuaNum)
		// {
		// 	for (uint8 i = 0; i < m_ui8HuaPaiList.size(); ++i)
		// 	{
		// 		if (i == ui8PlayerPosID)
		// 			continue;
		// 		for (uint j = 0; j < m_ui8HuaPaiList[i].size(); ++j)
		// 		{
		// 			if (m_ui8HuaPaiList[i][j] <= 68 && m_ui8HuaPaiList[i][j] >= 61)
		// 				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_PeiHuaHu);
		// 		}
		// 	}
		// }

		//全求人
		if ((((m_ui8UserAction[ui8PlayerPosID] & WIK_LEFT) == WIK_LEFT) || ((m_ui8UserAction[ui8PlayerPosID] & WIK_CENTER) == WIK_CENTER) || ((m_ui8UserAction[ui8PlayerPosID] & WIK_RIGHT) == WIK_RIGHT)) && ((m_ui8UserAction[ui8PlayerPosID] & WIK_PENG) == WIK_PENG) //只有吃碰
			&& (m_ui8UserCardIndex[ui8PlayerPosID].size() == 1)																																																			 //一张
			&& (m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[ui8PlayerPosID][0]) == m_ui8ProvideCard))																																								 //单吊
		{
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "全求人[%d]", enTaiType_QuanQiuRen);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_QuanQiuRen);
		}

		//门清自摸
		bool IsMqZm = false;
		if (m_uin8AddCardTai[ui8PlayerPosID].size())
		{
			//删除此翻型
            RemoveTaiType(ui8PlayerPosID, enTaiType_MenQing);
		}

		if (!m_WeaveItemArray[ui8PlayerPosID].size() && IsZiMo() && nIsRealHuPai[ui8PlayerPosID])
		{
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "门清自摸[%d]", enTaiType_MenQingZiMo);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_MenQingZiMo);
			nIsRealHuPai[ui8PlayerPosID] = false;
			IsMqZm = true;
		}

		if (IsZiMo() && !IsMqZm && nIsRealHuPai[ui8PlayerPosID])
		{//自摸
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "自摸[%d]", enTaiType_ZiMo);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_ZiMo);
		}

		if (((chr & en_HuPaiTaiType_MenQing).IsEmpty() == false) && !IsMqZm && nIsRealHuPai[ui8PlayerPosID])
		{ //门清
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "门清[%d]", enTaiType_MenQing);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_MenQing);
		}
		if ((chr & en_HuPaiTaiType_DuTin).IsEmpty() == false)
		{ //独听
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "独听[%d]", enTaiType_DuTing);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_DuTing);
		}

		//花杠
		if (m_ui8HuaPaiList[ui8PlayerPosID].size() == 4)
		{
			uint8 flower = 0;
			for (uint8 i = 0; i < m_ui8HuaPaiList[ui8PlayerPosID].size(); ++i)
			{
				flower += m_ui8HuaPaiList[ui8PlayerPosID][i];
			}
			if (flower == 250 || flower == 266) //春夏秋冬 || 梅兰竹菊
			{
				Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "花杠[%d]", enTaiType_HuaGang);
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_HuaGang);
			}
		}

		//庄台和连庄
		TWMJTablePlayers *pker = TO_TWMJTP(GetTablePlayerByPos(m_ui8BankerPos));
		if (pker->banker_count)
		{
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "连庄[%d]", enTaiType_LianLa);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_LianLa);
		}
		else
		{
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_ZhuangTai);
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "庄台：%d", enTaiType_ZhuangTai);
		}

		//风圈、风位
		uint8 count1 = 0, count2 = 0;
		std::vector<uint8> ui8CardData;
		uint8 userCard = m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[ui8PlayerPosID], ui8CardData);

		for (uint8 i = 0; i < userCard; ++i)
		{

			if (m_GameLogic->GetCardColor(ui8CardData[i]) == 4) //风牌
			{
				if (m_nRoundId == m_GameLogic->GetCardValue(ui8CardData[i]) - 1) //对应风牌
					++count1;
				if (GetFengWei(ui8PlayerPosID) == m_GameLogic->GetCardValue(ui8CardData[i]) - 1) //对应风牌
					++count2;
			}
		}
		if (count1 >= 3)
		{
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", " 风圈[%d]", enTaiType_FengQuan);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_FengQuan);
		}

		if (count2 >= 3)
		{
			Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", " 风位[%d]", enTaiType_FengWei);
			m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_FengWei);
		}

		//花台、三元
		uint8 count[3] = {0, 0, 0};
		bool dxsYuan = false;
		ui8CardData.clear();
		userCard = m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[ui8PlayerPosID], ui8CardData);
		for (uint8 i = 0; i < userCard; ++i)
		{
			if (m_GameLogic->GetCardColor(ui8CardData[i]) == 6) //花牌
			{
				if ((GetFengWei(ui8PlayerPosID) == m_GameLogic->GetCardValue(ui8CardData[i]) - 1) && m_GameLogic->GetCardValue(ui8CardData[i]) < 5)
				{
					Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", " 花台[%d]", enTaiType_HuaTai);
					m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_HuaTai);
				}

				if ((GetFengWei(ui8PlayerPosID) == m_GameLogic->GetCardValue(ui8CardData[i]) - 5) && m_GameLogic->GetCardValue(ui8CardData[i]) >= 5)
				{
					Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", " 花台[%d]", enTaiType_HuaTai);
					m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_HuaTai);
				}
			}

			if (m_GameLogic->GetCardColor(ui8CardData[i]) == 5) //箭牌
			{
				if (m_GameLogic->GetCardValue(ui8CardData[i]) == 1)
					count[0]++;
				if (m_GameLogic->GetCardValue(ui8CardData[i]) == 2)
					count[1]++;
				if (m_GameLogic->GetCardValue(ui8CardData[i]) == 3)
					count[2]++;
			}
		}

		if (m_uin8AddCardTai[ui8PlayerPosID].size())
		{

			if (AlreadyExisted(ui8PlayerPosID, enTaiType_XiaoSanYuan) || AlreadyExisted(ui8PlayerPosID, enTaiType_DaSanYuan))
			{
				//已有大小三元就不计算三元
				dxsYuan = true;
			}
		}
		if (!dxsYuan)
		{
			if (count[0] == 3)
			{
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_SanYuan);
				Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "三元[%d] ", enTaiType_SanYuan);
			}
			if (count[1] == 3)
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_SanYuan);
			if (count[2] == 3)
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_SanYuan);
		}

		if (m_ui8ProvidePos != ui8PlayerPosID)
		{ //如果胡牌的提供者不是自己
			if (IsQiangGang())
			{
				Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "抢杠胡[%d] ", enTaiType_QiangGangHu);
				//抢杠胡
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_QiangGangHu);
			}
		}

		if (m_bBaoTingHaveTai)
		{ //报听
			if (m_bBaoJiao[ui8PlayerPosID])
			{
				Log.Debug("TWMJAIChannelInterface::GetOtherTaiType", "报听[%d]", enTaiType_Baotin);
				m_uin8AddCardTai[ui8PlayerPosID].push_back(enTaiType_Baotin);
			}
		}

		m_GameLogic->LogDeBug(" TWMJAIChannelInterface::GetOtherTaiType", "---------player:%d ui32Result:%d --------------", ui8PlayerPosID, ui32Result);
		return ui32Result;
	}
	bool TWMJAIChannelInterface::RemoveTaiType(const uint8 &ui8CurrentPos, const uint8 &ui8Type)
	{
        std:vector<uint8>::iterator iter = m_uin8AddCardTai[ui8CurrentPos].begin();
		for (iter; iter != m_uin8AddCardTai[ui8CurrentPos].end(); ++iter)
		{
			if (*iter == ui8Type)
			{
				m_uin8AddCardTai[ui8CurrentPos].erase(iter);
			}
		}
		return true;
	}
	//获取玩家昵称
	const char *TWMJAIChannelInterface::GetPlayerName(TWMJTablePlayers player)
	{
		CharPtr pChr = sCharMgr.getByHandle((player).player._handle);
		return pChr->getStringField("name").c_str();
	}
	//获取风位
	uint8 TWMJAIChannelInterface::GetFengWei(const uint8 &ui8PlayerPosID)
	{
		for (uint8 i = 0; i < 4; ++i)
		{
			if (ui8PlayerPosID == (m_ui8DongFengSeat + i) % 4)
				return i;
		}
	}
	//获取胡牌番数
	uint32 TWMJAIChannelInterface::GetHuPaiFanShu(const uint8 &ui8PlayerPosID)
	{
		uint32 ui32FanShu = 0;
		uint32 ui32TaiType = GetHuPaiFanXing(ui8PlayerPosID);
		m_uin8AddCardTai[ui8PlayerPosID].push_back(ui32TaiType);
		Log.Debug("TWMJAIChannelInterface::GetHuPaiFanShu", "胡牌番型：%d", ui32TaiType);
		//胡牌番型
		switch (ui32TaiType)
		{
		case enTaiType_PingHu:
		{ //平胡
			printf("=================>>平胡<<===============%d\n", __LINE__);
			ui32FanShu = 2;
		}
		break;
		case enTaiType_XiaoSanYuan:
		{ //小三元
			printf("=================>>小三元<<===============%d\n", __LINE__);
			ui32FanShu = 4;
		}
		break;
		case enTaiType_DaSanYuan:
		{ //大三元
			printf("=================>>大三元<<===============%d\n", __LINE__);
			ui32FanShu = 8;
		}
		break;
		case enTaiType_QingYiSe:
		{ //清一色
			printf("=================>>清一色<<===============%d\n", __LINE__);
			ui32FanShu = 8;
		}
		break;
		case enTaiType_ZiYiSe:
		{ //字一色
			printf("=================>>字一色<<===============%d\n", __LINE__);
			ui32FanShu = 8;
		}
		break;
		case enTaiType_HunYiSe:
		{ //混一色
			printf("=================>>混一色<<===============%d\n", __LINE__);
			ui32FanShu = 4;
		}
		break;
		case enTaiType_SanAnKe:
		{ //三暗刻
			printf("=================>>三暗刻:%d<<===============%d\n", __LINE__);
			ui32FanShu = 2;
		}
		break;
		case enTaiType_SiAnKe:
		{ //四暗刻
			printf("=================>>四暗刻<<===============%d\n", __LINE__);
			ui32FanShu = 5;
		}
		break;
		case enTaiType_WuAnKe:
		{ //五暗刻
			printf("=================>>五暗刻<<===============%d\n", __LINE__);
			ui32FanShu = 8;
		}
		break;
		case enTaiType_XiaoSiXi:
		{ //小四喜
			printf("=================>>小四喜<<===============%d\n", __LINE__);
			ui32FanShu = 8;
		}
		break;
		case enTaiType_DaSiXi:
		{ //大四喜
			printf("=================>>大四喜<<===============%d\n", __LINE__);
			ui32FanShu = 16;
		}
		break;
		case enTaiType_LiGuLiGu:
		{ //呖咕呖咕
			printf("=================>>呖咕呖咕<<===============%d\n", __LINE__);
			ui32FanShu = 8;
		}
		break;
		case enTaiType_PengPengHu:
		{ //碰碰胡
			printf("=================>>碰碰胡<<===============%d\n", __LINE__);
			ui32FanShu = 4;
		}
		break;
		default:
			break;
		}

		//其他番型
		GetOtherTaiType(ui8PlayerPosID);
		uint8 ui8Exist = m_uin8AddCardTai[ui8PlayerPosID].size();
		for (uint8 i = 0; i < ui8Exist; ++i)
		{
			Log.Debug("TWMJAIChannelInterface::GetHuPaiFanShu", "Otherfanxing[%d]", m_uin8AddCardTai[ui8PlayerPosID][i]);
			switch (m_uin8AddCardTai[ui8PlayerPosID][i])
			{
			case enTaiType_HaiDiLao:
			{ //海底捞
				printf("033[40;33m=================>>海底捞<<===============%d\n\033[5m", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_GangShangKaiHua:
			{ //杠上花
				printf("=================>>杠上花<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_TianHu:
			{ //天湖
				printf("=================>>天湖<<===============%d\n", __LINE__);
				ui32FanShu += 24;
			}
			break;
			case enTaiType_DiHu:
			{ //地胡
				printf("=================>>地胡<<===============%d\n", __LINE__);
				ui32FanShu += 16;
			}
			break;
			case enTaiType_RenHu:
			{ //人胡
				printf("=================>>人胡<<===============%d\n", __LINE__);
				ui32FanShu += 8;
			}
			break;
			case enTaiType_TianTin:
			{ //天听
				printf("=================>>天听<<===============%d\n", __LINE__);
				ui32FanShu += 16;
			}
			break;
			case enTaiType_DiTing:
			{ //地听
				printf("=================>>地听<<===============%d\n", __LINE__);
				ui32FanShu += 8;
			}
			break;
			case enTaiType_PeiHuaHu:
			{ //配花胡
				printf("=================>>配花胡<<===============%d\n", __LINE__);
				ui32FanShu += 4;
			}
			break;
			case enTaiType_QuanQiuRen:
			{ //全求人
				printf("=================>>全求人<<===============%d\n", __LINE__);
				ui32FanShu += 2;
			}
			break;
			case enTaiType_MenQingZiMo:
			{ //门清自摸
				printf("=================>>门清自摸<<===============%d\n", __LINE__);
				ui32FanShu += 3;
			}
			break;
			case enTaiType_HuaGang:
			{ //花杠
				printf("=================>>花杠<<===============%d\n", __LINE__);
				ui32FanShu += 2;
			}
			break;
			case enTaiType_ZhuangTai:
			{ //庄台
				printf("=================>>庄台<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_FengQuan:
			{ //风圈
				printf("=================>>风圈<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_FengWei:
			{ //风位
				printf("=================>>风位<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			// case enTaiType_LianLa:
			// { //连庄
			// 	printf("=================>>连庄<<===============%d\n", __LINE__);
			// 	TWMJTablePlayers *pker = TO_TWMJTP(GetTablePlayerByPos(m_ui8BankerPos));
			// 	ui32FanShu += (pker->banker_count) * 2;
			// }
			// break;
			case enTaiType_HuaTai:
			{ //花台
				printf("=================>>花台<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_BaXianGuoHai:
			{ //八仙过海
				printf("=================>>八仙过海<<===============%d\n", __LINE__);
				ui32FanShu += 8;
			}
			break;
			case enTaiType_QiQiangYi:
			{ //七抢一
				printf("=================>>七抢一<<===============%d\n", __LINE__);
				ui32FanShu += 8;
			}
			break;
			case enTaiType_QiangGangHu:
			{ //抢杠胡
				printf("=================>>抢杠胡<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_Baotin:
			{ //报听
				printf("=================>>报听<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_MenQing:
			{ //门清
				printf("=================>>门清<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_DuTing:
			{ //独听
				printf("=================>>独听<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;
			case enTaiType_SanYuan:
			{ //三元
				printf("=================>>三元<<===============%d\n", __LINE__);
				ui32FanShu += 1;
			}
			break;

			default:
				break;
			}
		}

		m_GameLogic->LogDeBug("TWMJAIChannelInterface::GetHuPaiFanShu", "player:%d ui32FanShu:%d", ui8PlayerPosID, ui32FanShu);

		return ui32FanShu;
	}
	//从Xml加载配置
	void TWMJAIChannelInterface::LoadTWMJXml(void)
	{
		m_AddTaiTypeGroup.clear();
		TiXmlDocument doc("../scripts_xml/twmjn/twmj.xml");
		if (!doc.LoadFile())
		{
			Log.Error("twmj Test", "load twmj.xml failed!");
			return;
		}

		TiXmlElement *pRoot = doc.RootElement();
		if (NULL == pRoot)
		{
			Log.Error("twmj Test", "twmj.xml have not root node!");
			return;
		}

		TiXmlElement *pNode = pRoot->FirstChildElement();
		while (pNode != NULL)
		{
			if (strcmp(pNode->Value(), "twmj_group") == 0)
			{

				AddTaiType bPR;
				//获取牌型相应配置信息
				bPR.Type = StringConverter::parseUnsignedInt(pNode->Attribute("typenum"));
				bPR.Num = 0;
				bPR.Mult = StringConverter::parseUnsignedInt(pNode->Attribute("multiple"));
				Log.Debug("TWMJAIChannelInterface::LoadTWMJXml", "Type[%u]  Mult[%u]", bPR.Type, bPR.Mult);
				std::map<uint8, AddTaiType>::iterator fit = m_AddTaiTypeGroup.find(bPR.Type);
				if (fit == m_AddTaiTypeGroup.end())
				{
					m_AddTaiTypeGroup.insert(std::make_pair(bPR.Type, bPR));
				}
				else
				{
					fit->second = bPR;
				}
			}
			pNode = pNode->NextSiblingElement();
		}

		Log.Debug("TWMJAIChannelInterface::LoadTWMJXml", "Load twmj.xml sucess Bounty size[%u] MedalOdds size[%u]", m_AddTaiTypeGroup.size());
	}
	//流局处理
	void TWMJAIChannelInterface::DealLiuJu()
	{
		m_ui8NextBankerPos = m_ui8BankerPos;
		// m_ui8NextBankerPos = (m_ui8BankerPos FX 1 + m_nMaxPlayerNum) %
		// m_nMaxPlayerNum;
	}
	//获取番数
	uint8 TWMJAIChannelInterface::getTaiTypeMult(const uint8 &num)
	{
		std::map<uint8, AddTaiType>::iterator fit = m_AddTaiTypeGroup.find(num);
		return (fit->second.Mult);
	}
	//获取胡牌玩家
	std::vector<uint8> TWMJAIChannelInterface::GetWinerPlayer()
	{
		std::vector<uint8> WinPlayer;
		for (uint8 i = 0; i != m_ChiHuRight.size(); ++i)
		{
			if (m_ChiHuRight[i].IsEmpty() == false)
			{
				Log.Debug("TWMJAIChannelInterface::GetWinerPlayer", "winplayer[%d] ", i);
				WinPlayer.push_back(i);
			}
		}
		return WinPlayer;
	}
	//流局判断
	bool TWMJAIChannelInterface::IsLiuJu()
	{

		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			std::vector<uint8> vecHandCard;
			TWMJTablePlayers *pPlayerTp = TO_TWMJTP(GetTablePlayerByPos(i));
			m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[i], vecHandCard);
			pPlayerTp->Handcard = vecHandCard;
			pPlayerTp->ChiPengGanglist = m_WeaveItemArray[i];
			//pPlayerTp->ChiPengGangLucre = AllGangLucre[i];
		}
		Log.Debug("TWMJAIChannelInterface::IsLiuJu", "m_uint8LeftCardCount:%d m_ui8LiuJuCardNum:%d ", m_uint8LeftCardCount, m_ui8LiuJuCardNum);
		return ((IsQiangGang() == false && IsFangPao() == false && IsZiMo() == false) && m_uint8LeftCardCount <= m_ui8LiuJuCardNum);
	}
	//检测番型是否已经存在
	bool TWMJAIChannelInterface::AlreadyExisted(const uint8 &ui8CurrentPos, const uint8 &ui8Type)
	{
		uint8 ui8addcard = m_uin8AddCardTai[ui8CurrentPos].size();
		for (uint8 i = 0; i < ui8addcard; ++i)
		{
			if (m_uin8AddCardTai[ui8CurrentPos][i] == ui8Type)
				return true;
		}

		return false;
	}
	//气枪一和八仙过海
	uint8 TWMJAIChannelInterface::QiAndBaTaiType(const uint8 &ui8CurrentPos, CChiHuRight &ChiHuRight, const bool Qi)
	{
		uint8 ui8Result = WIK_NULL;
		std::vector<uint8> ui8CardIndexTemp = m_ui8UserCardIndex[ui8CurrentPos];
		//花牌
		if (m_ui8HuaPaiList.size())
		{
			uint8 count = 0;
			for (uint8 i = 0; i < m_ui8HuaPaiList[ui8CurrentPos].size(); ++i)
			{
				if (m_ui8HuaPaiList[ui8CurrentPos][i] <= 68 && m_ui8HuaPaiList[ui8CurrentPos][i] >= 61)
					++count;
			}

			if (m_bQiQiangYi)
			{ //七抢一
				if (count == 7)
				{
					for (uint8 i = 0; i < m_ui8HuaPaiList.size(); ++i)
					{
						if (i == ui8CurrentPos)
							continue;
						for (uint8 j = 0; j < m_ui8HuaPaiList[i].size(); ++j)
						{
							if (m_ui8HuaPaiList[i][j] <= 68 && m_ui8HuaPaiList[i][j] >= 61)
							{
								if (!AlreadyExisted(ui8CurrentPos, enTaiType_QiQiangYi))
								{
									m_uin8AddCardTai[ui8CurrentPos].push_back(enTaiType_QiQiangYi);
									Log.Debug("TWMJAIChannelInterface::QiAndBaTaiType", "七抢一:%d  m_uin8AddCardTai[ui8CurrentPos].size[%d]: %d",
											  enTaiType_QiQiangYi, ui8CurrentPos, m_uin8AddCardTai[ui8CurrentPos].size());
								}
							}
						}
					}
					ui8Result |= WIK_CHI_HU;
					ChiHuRight |= 0x8000;
				}
			}

			//八仙过海
			if (count == 8 && Qi)
			{
				if (!AlreadyExisted(ui8CurrentPos, enTaiType_BaXianGuoHai))
				{
					m_uin8AddCardTai[ui8CurrentPos].push_back(enTaiType_BaXianGuoHai);
					Log.Debug("TWMJAIChannelInterface::QiAndBaTaiType", "八仙过海:%d ui8Result[%d] ", enTaiType_BaXianGuoHai, ui8Result);
				}
				ui8Result |= WIK_CHI_HU;
				ChiHuRight |= 0x8000;
			}
		}
		return ui8Result;
	}
	bool TWMJAIChannelInterface::IsSpecialHu(const uint8 &ui8PlayerPos)
	{
		CChiHuRight ChiHuRight;
		uint8 ui8Result = 255;
		uint8 ui8result = AnalyseHuCard(ui8PlayerPos, m_ui8UserCardIndex[ui8PlayerPos], m_WeaveItemArray[ui8PlayerPos], m_ui8ProvideCard, ChiHuRight);
		CChiHuRight temp = m_ChiHuRight[ui8PlayerPos];
		m_ChiHuRight[ui8PlayerPos] = ChiHuRight;
		if (GetHuPaiFanXing(ui8PlayerPos) == 0)
		{
			ui8Result = WIK_NULL;
		}
		ChiHuRight = m_ChiHuRight[ui8PlayerPos];
		m_ChiHuRight[ui8PlayerPos] = temp;
		if (!ui8Result && ui8result == WIK_CHI_HU)
			return true;
		else
			return false;
	}
	//允许吃碰杠
	bool TWMJAIChannelInterface::AllowCPG()
	{
		return (m_uint8LeftCardCount >= m_ui8LiuJuCardNum + 4) ? true : false;
	}
	//报听才能胡
	bool TWMJAIChannelInterface::OnlyAllowBaoTingHu(const uint8 &ui8CurrentPos)
	{
		Log.Debug("TWMJAIChannelInterface::OnlyAllowBaoTingHu", "m_bOnlyBaoTingHu[%d] m_bBaoJiao[%d]", m_bOnlyBaoTingHu, m_bBaoJiao[ui8CurrentPos]);
		if (m_bOnlyBaoTingHu)
		{
			if (m_bBaoJiao[ui8CurrentPos] || IgnoreBaoJiao(ui8CurrentPos))
				return true;
			else
				return false;
		}
		else
			return true;
	}
	//无视报听才能胡
	bool TWMJAIChannelInterface::IgnoreBaoJiao(const uint8 &ui8CurrentPos)
	{
		uint32 ui32Result = 0;
		uint32 ui32BuHuaNum = 0;									   //补牌
		uint32 ui32CommonNum = 0;									   //通用
		ui32CommonNum = m_uint8MaxCardNum - m_ui8MaxHandCount * 4 - 1; //最大牌数量 手牌数量 特殊
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			ui32BuHuaNum += m_ui8HuaPaiList[i].size();
		Log.Debug("TWMJAIChannelInterface::IgnoreBaoJiao", "ui32BuHuaNum[%d]", ui32BuHuaNum);
		std::vector<uint8> ui8CardIndexTemp = m_ui8UserCardIndex[ui8CurrentPos];
		bool isIgnore = false;

		uint8 ui8PlayerOutCardCount = 0;
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			ui8PlayerOutCardCount += m_ui8DiscardCard[i].size();
		}
		uint8 ui8PlayerWeaveCount = 0;
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			ui8PlayerWeaveCount += m_WeaveItemArray[i].size();
		}

		//庄家特权
		if (ui8CurrentPos == m_ui8BankerPos)
		{
			if (IsZiMo() && ui8PlayerOutCardCount == 0 && ui8PlayerWeaveCount == 0 
			&& (m_uint8LeftCardCount == (ui32CommonNum - ui32BuHuaNum)) ) //减去花牌、发的牌、
			{	//天胡
				isIgnore = true;
				Log.Debug("TWMJAIChannelInterface::IgnoreBaoJiao", "天胡:%d", isIgnore);
			}
		}
		else
		{ //闲家
			uint8 firstpos;
			for (uint8 i = 1; i <= m_nMaxPlayerNum; i++)
			{
				uint8 poos = ((m_ui8BankerPos + i) % m_nMaxPlayerNum);
				if (poos == ui8CurrentPos)
				{
					firstpos = i;
					break;
				}
			}
			uint8 ui8outcardnum = m_ui8DiscardCard[ui8CurrentPos].size();
			if (IsZiMo() && ui8outcardnum == 1 && ui8PlayerWeaveCount == 0 
			&& (m_uint8LeftCardCount == (ui32CommonNum - ui32BuHuaNum - firstpos)))
			{ //地胡
				isIgnore = true;
				Log.Debug("TWMJAIChannelInterface::IgnoreBaoJiao", "地胡:%d", isIgnore);
			}
		}

		//人胡
		if (IsFangPao() && (m_uint8LeftCardCount >= (ui32CommonNum - ui32BuHuaNum - 4))
		 && ui8PlayerWeaveCount == 0 )
		{
			isIgnore = true;
			Log.Debug("TWMJAIChannelInterface::IgnoreBaoJiao", "人胡:%d", isIgnore);
		}

		//花牌
		if (m_ui8HuaPaiList.size())
		{
			uint8 count = 0;
			for (uint8 i = 0; i < m_ui8HuaPaiList[ui8CurrentPos].size(); ++i)
			{
				if (m_ui8HuaPaiList[ui8CurrentPos][i] <= 68 && m_ui8HuaPaiList[ui8CurrentPos][i] >= 61)
					++count;
			}

			if (m_bQiQiangYi)
			{ //七抢一
				if (count == 7)
				{
					for (uint8 i = 0; i < m_ui8HuaPaiList.size(); ++i)
					{
						if (i == ui8CurrentPos)
							continue;
						for (uint j = 0; j < m_ui8HuaPaiList[i].size(); ++j)
						{
							if (m_ui8HuaPaiList[i][j] <= 68 && m_ui8HuaPaiList[i][j] >= 61)
								isIgnore = true;
							Log.Debug("TWMJAIChannelInterface::IgnoreBaoJiao", "七抢一:%d", isIgnore);
						}
					}
				}
			}

			//八仙过海
			if (count == 8)
			{
				isIgnore = true;
				Log.Debug("TWMJAIChannelInterface::IgnoreBaoJiao", "八仙过海:%d", isIgnore);
			}
		}
		Log.Debug("TWMJAIChannelInterface::IgnoreBaoJiao", "isIgnore:%d", isIgnore);
		return isIgnore;
	}
	//不允许点炮胡
	bool TWMJAIChannelInterface::DisAllowDianPaoHu()
	{
		return m_bOnlyZiMoHu;
	}
	//玩家出牌操作
	void TWMJAIChannelInterface::OperateDispatchCardData(const uint8 &ui8CurrentPos, const uint8 &ui8OperatorCard)
	{
		CChiHuRight ChiHuRight;
		m_nQiQiangYiPos = 255;
		if (!IsHuaPai(ui8OperatorCard))
		{

			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				if (i == ui8CurrentPos)
					continue;
				uint8 ui8result = QiAndBaTaiType(i, ChiHuRight, false);
				if (ui8result == WIK_CHI_HU)
				{
					m_nQiQiangYiPos = i;
					m_ui8UserAction[i] |= WIK_CHI_HU;
					m_next_run_status = en_MJChannelState_OperatorCard;
					break;
				}
			}
		}
	}
	//铜钱场追加处理
	void TWMJAIChannelInterface::DealTongQianChang()
	{
		CenterBattle cb;
		sCenterBattleMgr.GetCenterBattle(m_btLog.cb_id, &cb);
		std::vector<uint8> WinPlayer, StayPlayer = GetWinerPlayer();
		WorldPacket packet;
		MJBaseTablePlayer *pLoseTp = NULL;
		CharPtr pLoseChr;
		if (IsFangPao())
		{
			//放炮者
			pLoseTp = GetTablePlayerByPos(m_ui8ProvidePos);
			pLoseChr = sCharMgr.load(pLoseTp->player._handle);
		}
		Log.Debug("TWMJAIChannelInterface::DealTongQianChang", "WinPlayer.size[%d]", WinPlayer.size());
		if (WinPlayer.size() == 3 && (sGLMgr.GetItemNum(pLoseChr, cb.data1) < (-pLoseTp->winLurce)))
		{ //一炮三响
			int losescore = pLoseTp->winLurce;
			for (uint8 i = 0; i < WinPlayer.size(); ++i)
			{
				MJBaseTablePlayer *pWinTp = GetTablePlayerByPos(WinPlayer[i]);
				CharPtr pWinChr = sCharMgr.load(pWinTp->player._handle);

				if (m_btLog.club_id != 0)
				{
					if (sCenterClubMemberMgr.GetMemberCurrCoins(m_btLog.club_id, pWinChr) == 0)
						pWinTp->m_bClearClubScore = true;
				}
				if (pWinTp->winLurce <= pLoseTp->winLurce / 3)
				{ //不参加平分
					if (m_btLog.club_id == 0)
						sGLMgr.addItemNum(pWinChr, cb.data1, pWinTp->winLurce);
					else
						sCenterClubMemberMgr.AddMemberCurrCoins(m_btLog.club_id, pWinChr, pWinTp->winLurce);

					losescore -= pWinTp->winLurce;
					StayPlayer.erase(StayPlayer.begin() + i);

					if (sProtocolsMgr.CreateMJPlayerInfoPacket(&packet, pWinTp))
						sGLMgr.SendProtocolsToChr(pWinChr, &packet);
				}
			}
			if (StayPlayer.size())
			{ //参加平分
				Log.Debug("TWMJAIChannelInterface::DealTongQianChang", "StayPlayer.size[%d]", StayPlayer.size());
				for (uint8 i = 0; i < StayPlayer.size(); ++i)
				{
					MJBaseTablePlayer *pWinTp = GetTablePlayerByPos(WinPlayer[i]);
					CharPtr pWinChr = sCharMgr.load(pWinTp->player._handle);
					if (m_btLog.club_id != 0)
					{
						if (sCenterClubMemberMgr.GetMemberCurrCoins(m_btLog.club_id, pWinChr) == 0)
							pWinTp->m_bClearClubScore = true;
					}
					if (m_btLog.club_id == 0)
						sGLMgr.addItemNum(pWinChr, cb.data1, losescore / StayPlayer.size());
					else
						sCenterClubMemberMgr.AddMemberCurrCoins(m_btLog.club_id, pWinChr, losescore / StayPlayer.size());

					if (sProtocolsMgr.CreateMJPlayerInfoPacket(&packet, pWinTp))
						sGLMgr.SendProtocolsToChr(pWinChr, &packet);
				}
			}

			//放炮者
			if (m_btLog.club_id == 0)
				sGLMgr.addItemNum(pLoseChr, cb.data1, sGLMgr.GetItemNum(pLoseChr, cb.data1));
			else
				sCenterClubMemberMgr.AddMemberCurrCoins(m_btLog.club_id, pLoseChr, sGLMgr.GetItemNum(pLoseChr, cb.data1));
			sLogDataMgr.UpdateItemsInfoLog(pLoseChr, en_ST_Game, cb.data1, en_UNT_Add, sGLMgr.GetItemNum(pLoseChr, cb.data1), m_btLog.cb_id, m_Unit->getHandle());

			if (sProtocolsMgr.CreateMJPlayerInfoPacket(&packet, pLoseTp))
				sGLMgr.SendProtocolsToChr(pLoseChr, &packet);
		}

		else if (WinPlayer.size() != 3)
		{ //一家胡
			Log.Debug("TWMJAIChannelInterface::DealTongQianChang", "一家胡");
			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				MJBaseTablePlayer *pTp = GetTablePlayerByPos(i);
				if (pTp)
				{
					CharPtr pChr = sCharMgr.load(pTp->player._handle);
					if (pChr.isNull() == false)
					{
						if (m_btLog.club_id != 0)
							if (sCenterClubMemberMgr.GetMemberCurrCoins(m_btLog.club_id, pChr) == 0)
								pTp->m_bClearClubScore = true;

						//输家
						if (pTp->winLurce > 0)
						{ //带入金币低于赢取数额，则只能赢取带入金币数额
							if (sGLMgr.GetItemNum(pChr, cb.data1) < pTp->winLurce)
							{
								if (m_btLog.club_id == 0)
									sGLMgr.addItemNum(pChr, cb.data1, sGLMgr.GetItemNum(pChr, cb.data1));
								else
									sCenterClubMemberMgr.AddMemberCurrCoins(m_btLog.club_id, pChr, sGLMgr.GetItemNum(pChr, cb.data1));
								sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Game, cb.data1, en_UNT_Add, sGLMgr.GetItemNum(pChr, cb.data1), m_btLog.cb_id, m_Unit->getHandle());
							}
							else
							{
								if (m_btLog.club_id == 0)
									sGLMgr.addItemNum(pChr, cb.data1, pTp->winLurce);
								else
									sCenterClubMemberMgr.AddMemberCurrCoins(m_btLog.club_id, pChr, pTp->winLurce);
								sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Game, cb.data1, en_UNT_Add, pTp->winLurce, m_btLog.cb_id, m_Unit->getHandle());
							}
						}
						else if (pTp->winLurce < 0)
						{ //赢家
							if (sGLMgr.GetItemNum(pChr, cb.data1) > (-pTp->winLurce))
							{
								if (m_btLog.club_id == 0)
									sGLMgr.reduceItemNum(pChr, cb.data1, (-pTp->winLurce));
								else
									sCenterClubMemberMgr.ReduceMemberCurrCoins(m_btLog.club_id, pChr, (-pTp->winLurce));
							}
							else
							{ //不够赔付，有多少赔多少
								if (m_btLog.club_id == 0)
									sGLMgr.SetItemNum(pChr, cb.data1, 0);
								else
									sCenterClubMemberMgr.ReduceMemberCurrCoins(m_btLog.club_id, pChr, sCenterClubMemberMgr.GetMemberCurrCoins(m_btLog.club_id, pChr));
							}
							sLogDataMgr.UpdateItemsInfoLog(pChr, en_ST_Game, cb.data1, en_UNT_Reduce, (-pTp->winLurce), m_btLog.cb_id, m_Unit->getHandle());
						}
						WorldPacket packet;
						if (sProtocolsMgr.CreateMJPlayerInfoPacket(&packet, pTp))
							sGLMgr.SendProtocolsToChr(pChr, &packet);
					}
				}
			}
		}
	}
	/************************吃胡结算************************/
	void TWMJAIChannelInterface::DealFangPao(const uint8 &ui8ProvidePos)
	{
		Log.Debug("TWMJAIChannelInterface::DealFangPao", "吃胡");
		std::vector<uint8> WinPlayer = GetWinerPlayer();
		int score = 0;
		int losescore = 0;
		bool isNextbanker = false;
		uint32 ui32FanShu = 0;
		TWMJTablePlayers *pker = TO_TWMJTP(GetTablePlayerByPos(m_ui8BankerPos));
		if(!pker->banker_count)
			ui32FanShu = 1;
		else
			ui32FanShu = (pker->banker_count) * 2;


		for(uint8 i = 0; i < WinPlayer.size(); ++i)
		{
			std::vector<uint8> vecHandCard;
			TWMJTablePlayers *pWinerTp =TO_TWMJTP(GetTablePlayerByPos(WinPlayer[i]));
			m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[WinPlayer[i]],vecHandCard);
			uint8 FanShu = (GetHuPaiFanShu(WinPlayer[i]));
			
			score = m_nBasePoint + (FanShu * m_nTaiScore); //底分 + 台数 *　台分
			if(m_ui8BankerPos == WinPlayer[i])
				score += ui32FanShu * m_nTaiScore;

			pWinerTp->winLurce += score;
			pWinerTp->score += score;
			pWinerTp->PlayerPower = GetHuPaiFanXing(WinPlayer[i]);
			pWinerTp->PlayerType = enHuType_QiangGangHu;
			if (IsSpecialHu(WinPlayer[i]))
			{
				Log.Debug("TWMJAIChannelInterface::DealFangPao", "花胡[%d]", enHuType_HuaHu);
				pWinerTp->PlayerType = enHuType_HuaHu;
			}

			pWinerTp->Handcard = vecHandCard;
			pWinerTp->ChiPengGanglist = m_WeaveItemArray[WinPlayer[i]];

			if (m_uin8AddCardTai[WinPlayer[i]].size())
			{ //其他加番信息统计
				uint8 firstTai = 0;
				AddTaiType cardtai;
				uint8 ui8TaiNum = m_uin8AddCardTai[WinPlayer[i]].size();

				for (uint8 k = 0; k < ui8TaiNum; ++k)
				{
					if (m_uin8AddCardTai[WinPlayer[i]][k])
					{
						cardtai.Type = m_uin8AddCardTai[WinPlayer[i]][k];
						cardtai.Mult = getTaiTypeMult(m_uin8AddCardTai[WinPlayer[i]][k]);
						cardtai.Num = 1;
						if (cardtai.Type == 5)
							cardtai.Num = pker->banker_count;

						for (uint8 j = 0; j < ui8TaiNum; ++j)
						{
							if (k != j)
							{
								if (m_uin8AddCardTai[WinPlayer[i]][k] == m_uin8AddCardTai[WinPlayer[i]][j])
								{
									cardtai.Num += 1;
									Log.Debug("TWMJAIChannelInterface::DealFangPao", "cardtai.Num:%d ", cardtai.Num);
								}
							}
						}
					}
					std::map<uint8, AddTaiType>::iterator fit =pWinerTp->AddTaiTypeList.find(cardtai.Type);
					if (fit == pWinerTp->AddTaiTypeList.end())
					{
						pWinerTp->AddTaiTypeList.insert(std::make_pair(cardtai.Type, cardtai));
					}
				}
			}

			losescore += score;
		}

		std::vector<uint8> vecHandCard;
		TWMJTablePlayers *pLoseTp = TO_TWMJTP(GetTablePlayerByPos(ui8ProvidePos));
		m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[ui8ProvidePos], vecHandCard);

		if (WinPlayer.size() == 3)
		{ //一炮三响

			if (m_ui8BankerPos == pLoseTp->pos)
			{
				pLoseTp->winLurce -= (losescore + ui32FanShu * m_nTaiScore * 3);
				pLoseTp->score -= (losescore + ui32FanShu * m_nTaiScore * 3);
				for (uint8 i = 0; i < WinPlayer.size(); ++i)
				{
					TWMJTablePlayers *pWinerTp = TO_TWMJTP(GetTablePlayerByPos(WinPlayer[i]));
					pWinerTp->winLurce += ui32FanShu * m_nTaiScore;
					pWinerTp->score += ui32FanShu * m_nTaiScore;
				}
			}
			else
			{
				pLoseTp->winLurce -= (losescore + ui32FanShu * m_nTaiScore);
				pLoseTp->score -= (losescore + ui32FanShu * m_nTaiScore);
			}

			isNextbanker = true;
		}
		else if (WinPlayer.size() == 1)
		{ //一家胡
			for (uint8 i = 0; i < m_nMaxPlayerNum; ++i)
			{
				if (i == ui8ProvidePos)
				{
					if (ui8ProvidePos == m_ui8BankerPos)
					{
						pLoseTp->winLurce -= (losescore + ui32FanShu * m_nTaiScore);
						pLoseTp->score -= (losescore + ui32FanShu * m_nTaiScore);
						TWMJTablePlayers *pWinerTp = TO_TWMJTP(GetTablePlayerByPos(WinPlayer[0]));
						pWinerTp->winLurce += ui32FanShu * m_nTaiScore;
						pWinerTp->score += ui32FanShu * m_nTaiScore;
					}
					else
					{
						pLoseTp->winLurce -= losescore;
						pLoseTp->score -= losescore;
					}

				}
				else if (i != WinPlayer[0])
				{
					TWMJTablePlayers *pCurrTp = TO_TWMJTP(GetTablePlayerByPos(i));
					m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[i], vecHandCard);
					pCurrTp->Handcard = vecHandCard;
					pCurrTp->ChiPengGanglist = m_WeaveItemArray[i];
					// pCurrTp->ChiPengGangLucre = AllGangLucre[i];
				}
			}

			if (WinPlayer[0] == m_ui8BankerPos)
				isNextbanker = true;
		}
		pLoseTp->Handcard = vecHandCard;
		pLoseTp->ChiPengGanglist = m_WeaveItemArray[ui8ProvidePos];
		// pLoseTp->ChiPengGangLucre = AllGangLucre[ui8ProvidePos];

		m_ui8NextBankerPos = (m_ui8BankerPos FX 1 + m_nMaxPlayerNum) % m_nMaxPlayerNum;
		TWMJTablePlayers *pCurrTp = TO_TWMJTP(GetTablePlayerByPos(m_ui8NextBankerPos));
		Log.Debug("TWMJAIChannelInterface::DealFangPao", "下一庄家[%s]：%d",GetPlayerName(*pCurrTp), m_ui8NextBankerPos);
		//连庄
		if (isNextbanker)
		{
			m_ui8NextBankerPos = m_ui8BankerPos;
			Log.Debug("TWMJAIChannelInterface::DealFangPao",
					  "一家胡或庄家胡继续当庄。。");
		}
		m_ui8LastBankerPos = m_ui8BankerPos;
	}
	//抢杠处理
	void TWMJAIChannelInterface::DealQiangGang(const uint8 &ui8ProvidePos)
	{
		DealFangPao(ui8ProvidePos);
	}
	/****************************自摸结算********************************/
	void TWMJAIChannelInterface::DealZiMo(const uint8 &ui8CurrentPos)
	{
		Log.Debug("TWMJAIChannelInterface::DealZiMo", "自摸胡");
		std::vector<uint8> WinPlayer = GetWinerPlayer();
		int score = 0;
		int winscore = 0;
		bool isNextbanker = false;
		int nFanshu = (GetHuPaiFanShu(ui8CurrentPos));
		int nBasePoint = m_nBasePoint;
		uint32 ui32FanShu = 0;
		Log.Debug("TWMJAIChannelInterface::DealZiMo", "nFanshu:[%d] m_nTaiScore[%d]", nFanshu, m_nTaiScore);
		TWMJTablePlayers *pker = TO_TWMJTP(GetTablePlayerByPos(m_ui8BankerPos));

		//如果没有连庄就计算庄台否则计算连N拉N
		if (!pker->banker_count)
			ui32FanShu = 1;
		else
			ui32FanShu = (pker->banker_count) * 2;

		//花胡与自摸
		TWMJTablePlayers *pWinerTp = TO_TWMJTP(GetTablePlayerByPos(ui8CurrentPos));
		if (IsSpecialHu(ui8CurrentPos))
		{
			Log.Debug("TWMJAIChannelInterface::DealZiMo", "花胡[%d]", enHuType_HuaHu);
			pWinerTp->PlayerType = enHuType_HuaHu;
		}
		else
		{
			if (!m_ui8BuCard)
			{	//八仙过海补花后自摸，只算自摸删除八仙过海
				if (AlreadyExisted(ui8CurrentPos, enTaiType_BaXianGuoHai))
				{
					RemoveTaiType(ui8CurrentPos, enTaiType_BaXianGuoHai);
					nFanshu -= 8;
				}
			}
			
			if (!AlreadyExisted(ui8CurrentPos, enTaiType_MenQingZiMo))
				pWinerTp->PlayerType = enHuType_ZiMo;
		}


		score = (nBasePoint + (nFanshu * m_nTaiScore));
		//庄家自摸
		if (m_ui8BankerPos == ui8CurrentPos)
				score += ui32FanShu * m_nTaiScore;
		//自摸玩家算分		
		pWinerTp->winLurce += score * 3;
		pWinerTp->score += score * 3;
		pWinerTp->PlayerPower = GetHuPaiFanXing(ui8CurrentPos);
			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{//其他玩家算分
				std::vector<uint8> vecHandCard;
				TWMJTablePlayers *pLoseTp = TO_TWMJTP(GetTablePlayerByPos(i));
				pLoseTp->Handcard = vecHandCard;
				pLoseTp->ChiPengGanglist = m_WeaveItemArray[i];
				//pLoseTp->ChiPengGangLucre = AllGangLucre[i];

				if (i == ui8CurrentPos)
					continue;
				pLoseTp->winLurce -= score;
				pLoseTp->score -= score;

				if (m_ui8BankerPos != ui8CurrentPos)
				{//如果庄家在其他三个玩家中
					if (i == m_ui8BankerPos)
					{//当庄者多赔庄台或连N
						pLoseTp->winLurce -= (ui32FanShu * m_nTaiScore);
						pLoseTp->score -= (ui32FanShu * m_nTaiScore);
						pWinerTp->winLurce += (ui32FanShu * m_nTaiScore);
						pWinerTp->score += (ui32FanShu * m_nTaiScore);
					}
				}
			}
		Log.Debug("TWMJAIChannelInterface::DealZiMo", "winLurce: %d", pWinerTp->winLurce);

		if (m_uin8AddCardTai[ui8CurrentPos].size())
		{ //番型信息统计
			uint8 firstTai = 0;
			AddTaiType cardtai;
			uint8 ui8TaiNum = m_uin8AddCardTai[ui8CurrentPos].size();//番型数
			Log.Debug("TWMJAIChannelInterface::DealZiMo", "ui8TaiNum: %d", ui8TaiNum);
			for (uint8 k = 0; k < ui8TaiNum; ++k)
			{
				if (m_uin8AddCardTai[ui8CurrentPos][k])
				{//存在该番型
					cardtai.Type = m_uin8AddCardTai[ui8CurrentPos][k];
					cardtai.Mult = getTaiTypeMult(m_uin8AddCardTai[ui8CurrentPos][k]);
					cardtai.Num = 1;
					for (uint8 j = 0; j < ui8TaiNum; ++j)
					{//统计该番型出现次数
						if (k != j)
						{
							if (m_uin8AddCardTai[ui8CurrentPos][k] == m_uin8AddCardTai[ui8CurrentPos][j])
							{
								cardtai.Num += 1;
								Log.Debug("TWMJAIChannelInterface::DealZiMo", "cardtai.Num:%d ", cardtai.Num);
							}
						}
					}
				}
				Log.Notice("TWMJAIChannelInterface::DealZiMo", "Type[%d] Mult[%d] Num[%d] ", cardtai.Type, cardtai.Mult, cardtai.Num);
				std::map<uint8, AddTaiType>::iterator fit = pWinerTp->AddTaiTypeList.find(cardtai.Type);
				if (fit == pWinerTp->AddTaiTypeList.end())
				{
					pWinerTp->AddTaiTypeList.insert(std::make_pair(cardtai.Type, cardtai));
				}
				//Log.Debug("TWMJAIChannelInterface::DealZiMo", "i: %d", i);
			}
		}

		m_ui8NextBankerPos = (m_ui8BankerPos FX 1 + m_nMaxPlayerNum) % m_nMaxPlayerNum;
		Log.Debug("TWMJAIChannelInterface::DealZiMo", "下一庄家[%s]：%d", GetPlayerName(*pWinerTp), m_ui8NextBankerPos);
		//连庄
		if (ui8CurrentPos == m_ui8BankerPos)
		{
			Log.Debug("TWMJAIChannelInterface::DealZiMo", "庄家自摸胡牌继续当庄。。");
			m_ui8NextBankerPos = m_ui8BankerPos;
		}
		m_ui8LastBankerPos = m_ui8BankerPos;
	}
	//追加处理
	void TWMJAIChannelInterface::AttachedAccounts()
	{
		Log.Debug("TWMJAIChannelInterface::AttachedAccounts", "结算");
		WorldPacket packet;
		if (sProtocolsMgr.CreateJieSuanPacket(&packet, m_vSeatPlayers, m_ui8HuaPaiList))
			BroadcastPacket(&packet);
	}
	//通知牌桌状态
	void TWMJAIChannelInterface::SendTableStatus(const uint32 &serial, bool bReconnection)
	{
		CMD_GameStart GameStart;
		if (IsGameStart())
		{
			GameStart.ui8BankerPos = m_ui8BankerPos;
			GameStart.ui8DongFengSeat = m_ui8DongFengSeat;
			GameStart.ui8GameStatus = bReconnection ? enMJGaneStats_Reconnection : enMJGaneStats_Gameing;
			GameStart.ui8LeftCardCount = m_uint8MaxCardNum;
			GameStart.vecDicePoint = m_dice;
			GameStart.ui8SendCardPos = (m_dice[0] + m_dice[1] + m_dice[2]) % m_nMaxPlayerNum;
			GameStart.ui8FirstDispatchCardPos = (m_dice[2] + m_dice[3]);
		}
		else
		{
			GameStart.ui8BankerPos = m_ui8BankerPos;
			GameStart.ui8DongFengSeat = m_ui8DongFengSeat;
			GameStart.ui8GameStatus = enMJGaneStats_Pre;
			GameStart.ui8LeftCardCount = 0;
			GameStart.vecDicePoint = m_dice;
			GameStart.ui8SendCardPos = (m_dice[0] + m_dice[1] + m_dice[2]) % m_nMaxPlayerNum;
			GameStart.ui8FirstDispatchCardPos = (m_dice[2] + m_dice[3]);
		}
		WorldPacket packet;

		if (sProtocolsMgr.CreateMJGameStatusPacket(&packet, GameStart))
		{
			if (serial == 0)
				BroadcastPacket(&packet);
			else
			{
				m_GameLogic->LogDeBug("TWMJAIChannelInterface::SendTableStatus, ", "SendTableStatus,m_nMaxPlayerNum:%d", m_nMaxPlayerNum);
				SendProtocolToPlayer(&packet, GetTablePlayer(serial));
			}
		}
	}
	// 定庄Update
	HSMStateHandler TWMJAIChannelInterface::ChannelBattleChooseBankerUpdate(void)
	{
		WGS_CHANNEL_LOCK;
		if (m_next_run_status == en_MJChannelState_GameOverCalc)
			return ChangeChannelState(m_next_run_status);
		if (m_status_endtimer <= now())
		{// 定庄时间到，发牌
		
			m_next_run_status = en_MJChannelState_SendCards;
			return ChangeChannelState(m_next_run_status);
		}

		return 0;
	}
	//初始话自定义状态函数
	void TWMJAIChannelInterface::InitPublicFun()
	{
		m_mapStateInit.clear();
		m_mapStateUpdate.clear();
		// m_mapStateInit[KOUPAI] = TO_StateInit(setChannelBattleKouPai);
		// m_mapStateUpdate[KOUPAI] = TO_StateUpdate(ChannelBattleKouPaiUpdate);
	}
	//胡牌分析
	uint8 TWMJAIChannelInterface::AnalyseHuCard(const uint8 & ui8PlayerPosID, std::vector<uint8>& ui8CardIndex, std::vector<tagWeaveItem> WeaveItem, uint8 ui8CurrentCard, CChiHuRight & ChiHuRight)
	{
		uint8	ui8Result = WIK_NULL;
		std::vector<tagAnalyseItem> AnalyseItemArray;
		ChiHuRight.SetEmpty();
		std::vector<uint8> ui8CardIndexTemp = ui8CardIndex;
		//复制手牌数据
		if (ui8CurrentCard == 0)
		{
			Log.Error("TWMJAIChannelInterface::AnalyseHuCard", "ui8CurrentCard error  :%d", ui8CurrentCard);
			//return 0;
			//ASSERT(0);
		}
		//将待判断的牌加入手牌
		if (ui8CurrentCard)
			ui8CardIndexTemp[m_GameLogic->SwitchToCardIndex(ui8CurrentCard)]++;
		uint8 ui8OutMagicCard = ui8CurrentCard;
		if (m_bOutMagicCard || (m_run_status == en_MJChannelState_GiveCard || (m_run_status == en_MJChannelState_OperatorCard && m_ui8CurrentPos != INVALID_uint8)))
			ui8OutMagicCard = 0;
		if (ui8OutMagicCard != 0)
		{
			std::vector<uint8> outTemp;
			outTemp.push_back(ui8OutMagicCard);
			m_GameLogic->SetMagicCardOff(outTemp);
		}
		else
		{
			std::vector<uint8> outTemp;
			m_GameLogic->SetMagicCardOff(outTemp);
		}

		ui8Result |= m_GameLogic->CheckHuPaiTypeBeforeAnalyse(ui8CardIndexTemp, WeaveItem, ui8CurrentCard, ChiHuRight);

		if (ui8Result != WIK_NULL)
		{
			CChiHuRight temp = m_ChiHuRight[ui8PlayerPosID];
			m_ChiHuRight[ui8PlayerPosID] = ChiHuRight;
			if (GetHuPaiFanXing(ui8PlayerPosID) == 0)
			{
				ui8Result = WIK_NULL;
			}
			else
			{
				nIsRealHuPai[ui8PlayerPosID] = true;
			}
			ChiHuRight = m_ChiHuRight[ui8PlayerPosID];
			m_ChiHuRight[ui8PlayerPosID] = temp;
		}

		//分析手牌

		m_GameLogic->AnalyseCard(ui8CardIndexTemp, WeaveItem, AnalyseItemArray);

		if (AnalyseItemArray.empty() == false)
		{
			ui8Result |= WIK_CHI_HU;
			ChiHuRight |= 1;
			nIsRealHuPai[ui8PlayerPosID] = true;
		}
		for (uint8 i = 0; i < AnalyseItemArray.size(); i++)
		{
			//Log.Debug("TWMJAIChannelInterface::AnalyseHuCard", "AnalyseItemArray.size[%d]", AnalyseItemArray.size());
			tagAnalyseItem * pAnalyseItem = &AnalyseItemArray[i];
			m_GameLogic->CheckHuPaiTypeAfterAnalyse(pAnalyseItem, WeaveItem, ui8CurrentCard, ChiHuRight);
		}

		//七抢一和八仙过海
		uint8 ui8result = QiAndBaTaiType(ui8PlayerPosID, ChiHuRight,true);
		if (ui8result != WIK_NULL)
		{
			ui8Result = ui8result;
			//Log.Debug("TWMJAIChannelInterface::AnalyseHuCard", "ui8result[%d]", ui8result);
		}

		return ui8Result;
	}
	//随机产生庄家
	void TWMJAIChannelInterface::MakeRandBanker()
	{
		// 随机庄家
		do
		{

			uint32 point = m_dice[0] + m_dice[1] + m_dice[2];
			switch (point)
			{
			case 5:
			case 9:
			case 13:
			case 17:

				m_ui8BankerPos = 0;
				break;
			case 6:
			case 10:
			case 14:
			case 18:
				m_ui8BankerPos = 1;
				break;
			case 3:
			case 7:
			case 11:
			case 15:
				m_ui8BankerPos = 2;
				break;
			case 4:
			case 8:
			case 12:
			case 16:
				m_ui8BankerPos = 3;
				break;
			}
		} while (m_ui8BankerPos > m_nMaxPlayerNum - 1);
	}
	/*void TWMJAIChannelInterface::TestHandCards()
	{
		if (false)
		{
			// printf("\n TestHandCards num: %d  ---------------------\n\n");
                        uint8 byte[] = {
                            11, 12, 13, 14, 15, 16, 17, 18, 19, //万子
                            11, 12, 13, 14, 15, 16, 17, 18, 19, //万子
                            11, 12, 13, 14, 15, 16, 17, 18, 19, //万子
                            11, 12, 13, 14, 15, 16, 17, 18, 19, //万子

                            21, 22, 23, 24, 25, 26, 27, //28, 29, //同子
                            //21, 22, 23, 24, 25, 26, 27, 28, 29, //同子
                            // 21, 22, 23, 24, 25, 26, 27, 28, 29, //同子
                            21, 22, 23, 24, 25, //26, 27, 28, 29, //同子

                            // 31, 32, 33, 34, 35, 36, 37, 38, 39, //索子
                            // 31, 32, 33, 34, 35, 36, 37, 38, 39, //索子
                            // 31, 32, 33, 34, 35, 36, 37, 38, 39, //索子
                            // 31, 32, 33, 34, 35, 36, 37, 38, 39, //索子

                            41, 41, 41, 41, //东风
                            42, 42, 42, 42, //南风
                            43, 43, 43, 43, //西风
                            44, 44, 44, 44, //北风

                            51, 51, 51, 51, //中
                            52, 52, 52, 52, //发
                            //53, 53, 53, 53, //白

                            53, 
                            62, //夏
                            53, 
                            64, //冬
                            53,
                            66, //兰
                            53, 
                            68, //菊

                            18, 43, 42, 42, 44, 44, 11, 11, 11, 51, 52, 53, 53, 65, 43, 44,


                            18, 18, 44, 44, 43, 43, 42, 42, 52, 52, 22, 25, 22, 61, 53, 16,

                            29, 29, 29, 29, 28, 28, 28, 28, 18, 18, 18, 18, 28, 62, 53, 16,

                            41, 42, 44, 51, 15, 15, 15, 15, 21, 21, 21, 21, 15, 67, 53, 16,


                        };
                        std::vector<uint8> temp(byte, byte + MAX_REPERTORY_HUA );
			m_uint8RepertoryCard = temp;
			m_ui8BankerPos = 3;

		}
	}*/
	//发送胡牌情况
	void TWMJAIChannelInterface::SendHuPaiInfo(uint8 ui8PlyaerChairID)
	{
		Log.Debug("TWMJAIChannelInterface::SendHuPaiInfo", "");

		//一炮多响处理
		std::vector<uint8> winplayer = GetWinerPlayer();
		if(winplayer.size() == 2)
		{
			if(!GetRelativePos(m_ui8ProvidePos, winplayer[0]))
				m_ChiHuRight[winplayer[0]].SetEmpty();
			else if(!GetRelativePos(m_ui8ProvidePos, winplayer[1]))
				m_ChiHuRight[winplayer[1]].SetEmpty();
			else
				m_ChiHuRight[ GetRelativePos(m_ui8ProvidePos, winplayer[0]) < GetRelativePos(m_ui8ProvidePos, winplayer[1]) ? winplayer[1] : winplayer[0] ].SetEmpty();
		}

		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			Log.Debug("TWMJAIChannelInterface::SendHuPaiInfo", "i:%d ui8PlyaerChairID:%d", i, ui8PlyaerChairID);

			if (ui8PlyaerChairID == 0 || (i == ui8PlyaerChairID && ui8PlyaerChairID != 0))
			{
				MJBaseTablePlayer *pTp = GetTablePlayerByPos(i);
				Log.Debug("TWMJAIChannelInterface::SendHuPaiInfo", "i:%d m_ChiHuRight[i].IsEmpty():%d pTp->m_bSendHuPaiInfo:%d", i, m_ChiHuRight[i].IsEmpty(), pTp->m_bSendHuPaiInfo);

				if (pTp == NULL)
					continue;
				if (m_ChiHuRight[i].IsEmpty() == true || pTp->m_bSendHuPaiInfo == false)
				{ //玩家没有胡牌信息

					if (m_ui8ProvidePos == i)
					{
						MJBaseTablePlayer *pTp = GetTablePlayerByPos(i);
						pTp->dianPaoNum++;
					}

					continue;
				}
				uint8 ui8HuType = enHuType_Default;
				if (IsSpecialHu(i))
				{
					ui8HuType = enHuType_HuaHu;
				}
				else if(m_ui8ProvidePos == i)
				{ //如果胡牌的提供者是自己
					if (m_bGangKai)
						ui8HuType = enHuType_LingShangKaiHua;
					else
						ui8HuType = enHuType_ZiMo;
				}
				else
				{
					if (IsQiangGang())
					{
						ui8HuType = enHuType_QiangGangHu;
					}

					else
						ui8HuType = enHuType_Hu;
				}

				Log.Debug("TWMJAIChannelInterface::SendHuPaiInfo", "FZPID:%d m_ui8ProvidePos:%d i:%d ui8HuType:%d ", m_nFzPid, m_ui8ProvidePos, i, ui8HuType);

				std::vector<uint8> vecHandCard;
				if (m_ui8ChiHuCard)
					m_ui8UserCardIndex[i][m_GameLogic->SwitchToCardIndex(m_ui8ChiHuCard)]--;
				m_GameLogic->SwitchToCardData(m_ui8UserCardIndex[i], vecHandCard);
				WorldPacket packet;
				if (sProtocolsMgr.CreateMJOperateHuPacket(&packet,
														  i,
														  vecHandCard,
														  m_WeaveItemArray[i],
														  m_ui8ChiHuCard,
														  GetHuPaiFanXing(i),
														  m_ui8ProvidePos,
														  ui8HuType,
														  GetHuPaiExData(i)))
					BroadcastPacket(&packet);
				packet.clear();
				{
					packet << uint16(SMSS_MJ_OperateHu)
						   << uint16(0);
					packet << uint8(i)
						   << uint8(m_ui8ChiHuCard)
						   << uint8(ui8HuType);
					PlayBack(&packet);
				}
				if (pTp)
				{
					pTp->m_ui8ProvidePos = m_ui8ProvidePos;
					pTp->m_ui8HuPaiFanXing = GetHuPaiFanXing(i);
					pTp->m_ui8ChiHuCard = m_ui8ChiHuCard;
					pTp->m_ui8HuType = ui8HuType;
					pTp->m_ui32ExData = GetHuPaiExData(i);
					if (ui8HuType == enHuType_Hu)
						pTp->jiePaoNum++;
					if (ui8HuType == enHuType_ZiMo)
						pTp->ziMoNum++;
					if (ui8HuType == enHuType_LingShangKaiHua)
						pTp->gangshanghuaNum++;
					if (ui8HuType == enHuType_QiangGangHu)
						pTp->qiangGangNum++;
					pTp->m_bSendHuPaiInfo = false;
				}
			}
		}
	}
	//动作优先级											   须判断的动作			竞争者					执行者				动作提供者				牌列表
	uint8 TWMJAIChannelInterface::GetUserActionRank(uint8 ui8UserAction, uint8 ui8CureentUser, uint8 ui8TargetPos, uint8 ui8ProvidePos, std::vector<uint8> ui8CardData)
	{
		if (ui8UserAction & WIK_CHI_HU)
		{

			if (GetRelativePos(ui8ProvidePos, ui8CureentUser) == enPos_Down)
				return 7; //下家
			if (GetRelativePos(ui8ProvidePos, ui8CureentUser) == enPos_Medium)
				return 6; //对家
			return 5;
		}

		if (ui8UserAction & WIK_GANG)
			return 4;
		if (ui8UserAction & WIK_PENG)
			return 2;
		if (ui8UserAction & (WIK_RIGHT | WIK_CENTER | WIK_LEFT))
			return 1;
		return 0;
	}
	//出牌响应
	bool TWMJAIChannelInterface::EstimateUserRespond(const uint8 &ui8CurrentPos, const uint8 &ui8CenterCard, const uint8 &EstimatKind)
	{
		VecInit<uint8>(m_bResponse, m_nMaxPlayerNum, false);
		VecInit<uint8>(m_ui8UserAction, m_nMaxPlayerNum, 0);
		VecInit<uint8>(m_ui8PerformAction, m_nMaxPlayerNum, 0);

		bool isAnyAction = false;

		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			if (i == ui8CurrentPos || m_bPlayStatus[i] == false)
				continue;
			Log.Debug("TWMJAIChannelInterface::EstimateUserRespond", "i: %d", i);

			//吃
			if (m_GameLogic->AllowedChi() && AllowCPG())
			{
				bool bChiPai = false;
				if (m_GameLogic->GetChiPaiMode() == enChiPaiMode_ShangJia)
				{
					if ((i + m_nMaxPlayerNum FX - 1) % m_nMaxPlayerNum == ui8CurrentPos)
					{
						bChiPai = true;
					}
				}
				else if (m_GameLogic->GetChiPaiMode() == enChiPaiMode_DuiJia)
				{
					if ((i + m_nMaxPlayerNum FX + 1) % m_nMaxPlayerNum != ui8CurrentPos)
					{
						bChiPai = true;
					}
				}
				if (bChiPai)
				{
					if (IsEstimateChi(ui8CurrentPos, i, ui8CenterCard))
					{
						Log.Debug("TWMJAIChannelInterface::EstimateUserRespond", "%d %d", (i + m_nMaxPlayerNum FX - 1) % m_nMaxPlayerNum, ui8CurrentPos);
						if (m_bBaoJiao[i] != true)
						{
							uint8 result = m_GameLogic->EstimateChiCard(m_ui8UserCardIndex[i], ui8CenterCard, m_VPlayerChiCardList[i]);
							m_ui8UserAction[i] |= result;
							if (result != WIK_NULL)
								isAnyAction = true;
						}
					}
				}
			}
			//碰
			if (m_GameLogic->AllowedPeng() && AllowCPG())
			{
				if (IsEstimatePeng(ui8CurrentPos, i, ui8CenterCard))
				{
					if (m_bBaoJiao[i] != true)
					{
						uint8 result = m_GameLogic->EstimatePengCard(m_ui8UserCardIndex[i], ui8CenterCard, m_VPlayerPengCardList[i]);
						m_ui8UserAction[i] |= result;
						if (result != WIK_NULL)
							isAnyAction = true;
					}
				}
			}

			//杠
			if (m_GameLogic->AllowedGang() && AllowCPG())
			{
				if (IsEstimateGang(ui8CurrentPos, i, ui8CenterCard))
				{
					uint8 result = m_GameLogic->EstimateGangCard(m_ui8UserCardIndex[i], ui8CenterCard, m_VPlayerGangCardList[i]);
					if (result != WIK_NULL)
					{
						if (m_bBaoJiao[i] == true || m_ui8Trustee[i] == enPlayer_AutoHuPai)
						{
							if (TingEstimateGang(i, ui8CenterCard))
							{
								isAnyAction = true;
								m_ui8UserAction[i] |= result;
							}
							else
								m_VPlayerGangCardList[i].clear();
						}
						else
						{
							m_ui8UserAction[i] |= result;
							isAnyAction = true;
						}
					}
				}
			}

			//胡牌判断（点炮）
			if (!DisAllowDianPaoHu() && OnlyAllowBaoTingHu(i))
			{
				Log.Debug("TWMJAIChannelInterface::EstimateUserRespond", "允许点炮胡[%d]", DisAllowDianPaoHu());
				if (IsEstimateHu(ui8CurrentPos, i, ui8CenterCard) && m_bEnjoinChiHu[i] == false)
				{
					CChiHuRight ChiHuRight;
					uint8 result = AnalyseHuCard(i, m_ui8UserCardIndex[i], m_WeaveItemArray[i], ui8CenterCard, ChiHuRight);
					m_ui8UserAction[i] |= result;
					Log.Debug("TWMJAIChannelInterface::EstimateUserRespond", "%d:``Hu:result:%d", i, result);
					if (result != WIK_NULL)
					{
						isAnyAction = true;
					}
				}
			}
		}

		if (isAnyAction)
		{
			m_ui8ProvidePos = ui8CurrentPos;
			m_ui8ProvideCard = ui8CenterCard;
			m_ui8ResumePos = m_ui8CurrentPos;
			m_ui8CurrentPos = INVALID_uint8;
			Log.Success("TWMJAIChannelInterface::EstimateUserRespond", "m_ui8ProvidePos[%d] m_ui8ProvideCard[%x] m_ui8ResumeUser[%d] ",
						m_ui8ProvidePos,
						m_ui8ProvideCard,
						m_ui8CurrentPos);
			m_next_run_status = en_MJChannelState_OperatorCard;

			//		setStatusEndTimer(/*sXmlDataMgr.getTCMJconf("A_SendCard")- 1000*/ 0);
		}

		return isAnyAction;
	}

	void TWMJAIChannelInterface::OperateGang(uint8 ui8CurrentPos, tagWeaveItem & _weaveItem)
	{
		MJConstantlyCale CCTemp;
		CCTemp.ui8Kind = _weaveItem.ui8WeaveKind;
		CCTemp.ui8Type = _weaveItem.ui8Type;
		uint8 Ppos = _weaveItem.ui8ProvidePos;
		
		PlayerGangShangPao[ui8CurrentPos] = 1;
		
		std::vector<MJScoreChange> vecPlyaerScoreChange(m_nMaxPlayerNum, MJScoreChange());
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			TWMJTablePlayers * pPlayer = TO_TWMJTP(GetTablePlayerByPos(i));
			if (pPlayer == NULL) continue;
			vecPlyaerScoreChange[i].nScore = pPlayer->score;
	
		}
		TWMJTablePlayers * pPlayer = TO_TWMJTP(GetTablePlayerByPos(ui8CurrentPos));
		if (pPlayer == NULL) return;
		// ++pPlayer->ui8GenNum;
		if (_weaveItem.ui8Type == enGangType_MingGang)
		{
			
			TWMJTablePlayers * pPay = TO_TWMJTP(GetTablePlayerByPos(Ppos));
			if (pPay)
			{
				GangLucre ganglucre;
				ganglucre.gangtype = enGangType_MingGang;
				ganglucre.pgangpos = Ppos;
				//AllGangLucre[Ppos].push_back(ganglucre);
			}
			
			
		}
		else if (_weaveItem.ui8Type == enGangType_AnGang)
		{
			CCTemp.ui8FanShu = 1;
			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				if (i == ui8CurrentPos ) continue;
				TWMJTablePlayers * pPay = TO_TWMJTP(GetTablePlayerByPos(i));
				if (pPay)
				{
					GangLucre ganglucre;
					ganglucre.gangtype = enGangType_AnGang;
					ganglucre.pgangpos = i;
					//AllGangLucre[i].push_back(ganglucre);
				}
			}
		}
		else if (_weaveItem.ui8Type == enGangType_MianXiaGang)
		{
			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				if (i == ui8CurrentPos) continue;
				TWMJTablePlayers * pPay = TO_TWMJTP(GetTablePlayerByPos(i));
				if (pPay)
				{
					GangLucre ganglucre;
					ganglucre.gangtype = enGangType_MianXiaGang;
					ganglucre.pgangpos = i;
					//AllGangLucre[i].push_back(ganglucre);
				}
			}
		}
		
		WorldPacket packet;
		if (sProtocolsMgr.CreateMJScoreChangePacket(&packet, vecPlyaerScoreChange))
			BroadcastPacket(&packet);

		//及时输赢
		for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
		{
			CCTemp.vecPlayerScore.push_back(vecPlyaerScoreChange[i].nScoreChange);
		}
		m_vecPlayerConstantlyCaleList.push_back(CCTemp);
		if (sProtocolsMgr.CreateMJConstantlyCalePacket(&packet, m_vecPlayerConstantlyCaleList))
			BroadcastPacket(&packet); 
		
	}

	bool TWMJAIChannelInterface::IsEstimatePeng(const uint8 &ui8CurrentPos, const uint8 &ui8EstimatePos, const uint8 &ui8CenterCard)
	{

	return true;
	}
	//判断是否能吃
	bool TWMJAIChannelInterface::IsEstimateChi(const uint8 &ui8CurrentPos, const uint8 &ui8EstimatePos, const uint8 &ui8CenterCard)
	{
		if (ui8EstimatePos != ((ui8CurrentPos - 1 + m_vSeatPlayers.size()) % m_vSeatPlayers.size()))
		{
			return false;
		}
		//同巡内不得吃入本家前一舍牌之同(络)牌.
		if (m_ui8OperateCard[ui8EstimatePos] == ui8CenterCard)
		{
			return false;
		}
			return true;
	}
	//判断
	void TWMJAIChannelInterface::OperateChi(uint8 ui8CurrentPos, tagWeaveItem &_weaveItem)
	{
		 //不能打出与吃牌牌型相同的牌
		if (m_ui8ProvideCard == _weaveItem.ui8CardData[0] || m_ui8ProvideCard == _weaveItem.ui8CardData[2])
		{
			m_vecNoOutCardsIndex[ui8CurrentPos].push_back(m_GameLogic->SwitchToCardIndex(_weaveItem.ui8CardData[0]));
			m_vecNoOutCardsIndex[ui8CurrentPos].push_back(m_GameLogic->SwitchToCardIndex(_weaveItem.ui8CardData[2]));
		}
		if (m_ui8ProvideCard == _weaveItem.ui8CardData[1])
		{
			m_vecNoOutCardsIndex[ui8CurrentPos].push_back(m_GameLogic->SwitchToCardIndex(_weaveItem.ui8CardData[1]));
		}
	}

	//玩家操作
	bool TWMJAIChannelInterface::UserOperateCard(const uint8 &ui8PlayerPosID, const uint8 &ui8OperateCard, const uint8 &ui8OperateCode, std::vector<uint8> ui8CardData)
	{
		m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", "ui8PlayerPosID[%d] ui8OperateCard[%d] ui8OperateCode[%d]",
							  ui8PlayerPosID,
							  ui8OperateCard,
							  ui8OperateCode);
		m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", "m_ui8CurrentPos[%d] ",
							  m_ui8CurrentPos);
		if (m_run_status != en_MJChannelState_OperatorCard)
			return true;
		m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " en_MJChannelState_OperatorCard:%d m_nQiQiangYiPos:%d", en_MJChannelState_OperatorCard, m_nQiQiangYiPos);
		if (ui8PlayerPosID != m_ui8CurrentPos && m_ui8CurrentPos != INVALID_uint8 && ui8PlayerPosID == m_nQiQiangYiPos)
		{
			if(ui8OperateCode == WIK_CHI_HU)
			{
				m_ui8UserAction[m_ui8CurrentPos] =  0;
				m_ui8ProvidePos = m_ui8CurrentPos;
				m_ui8CurrentPos = INVALID_uint8;

				//m_ui8ProvideCard = m_uint8SendCardData;
			}
			else if(ui8OperateCode == WIK_NULL)
			{
				m_ui8UserAction[ui8PlayerPosID] = WIK_NULL;
				m_ui8PerformAction[ui8PlayerPosID] = WIK_NULL;

				if (!m_ui8UserAction[m_ui8CurrentPos])
				{
					m_next_run_status = en_MJChannelState_CastCard;
					return true;
				}
				
			}
		}

		m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8OperateCode:%d m_ui8CurrentPos:%d", ui8OperateCode, m_ui8CurrentPos);
		if (ui8PlayerPosID != m_ui8CurrentPos && m_ui8CurrentPos != INVALID_uint8)
		{
			WorldPacket packet;
			if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_TimeError))
				SendProtocolToPlayer(&packet, ui8PlayerPosID);
			return true;
		}
		if (m_ui8CurrentPos == INVALID_uint8)
		{ //其他玩家打牌后提供的操作
			if (m_bResponse[ui8PlayerPosID] == true)
			{
				WorldPacket packet;
				if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_Repeate))
					SendProtocolToPlayer(&packet, ui8PlayerPosID);
				m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", "m_bResponse[ui8PlayerPosID] == true ");
				return true;
			}
			if (ui8OperateCode != WIK_NULL && (m_ui8UserAction[ui8PlayerPosID] & ui8OperateCode) == 0)
			{
				WorldPacket packet;
				if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_Error))
					SendProtocolToPlayer(&packet, ui8PlayerPosID);
				m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " NO ACTION ");
				return true;
			}

			if (ui8OperateCode == WIK_CHI_HU)
			{
				if (m_bGuoShui[ui8PlayerPosID])
				{
					WorldPacket packet;
					if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_Error))
						SendProtocolToPlayer(&packet, ui8PlayerPosID);
					m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " m_bGuoShui = true");
					return true;
				}
			}

			uint8 ui8TargetPos = ui8PlayerPosID;
			uint8 ui8TargetAction = ui8OperateCode;

			//------------优先级判断

			m_bResponse[ui8PlayerPosID] = true;
			m_ui8PerformAction[ui8PlayerPosID] = ui8OperateCode;
			m_ui8OperateCard[ui8PlayerPosID] = ui8OperateCard; //所吃的牌
			m_ui8TargetCardData[ui8PlayerPosID] = ui8CardData;

			//在自己未摸下一张牌的一圈内,不能弃上一家而胡下一家
			if (ui8TargetAction == WIK_NULL && (WIK_CHI_HU & m_ui8UserAction[ui8TargetPos]) &&
				m_ui8ProvidePos != ui8TargetPos)
			{
				if(!m_bNotAllowGuoShui)
				{//不得过水
					m_bEnjoinChiHu[ui8TargetPos] = true;
					m_vecLouHuCards[ui8TargetPos].push_back(m_ui8ProvideCard);
				}

			}
			OperateGuo(ui8PlayerPosID, ui8OperateCard, m_ui8UserAction[ui8PlayerPosID]);

			//判断
			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				//获取玩家动作
				uint8 pos = (ui8PlayerPosID + i + m_nMaxPlayerNum) % m_nMaxPlayerNum;
				uint8 ui8UserAction = (m_bResponse[pos] == false) ? m_ui8UserAction[pos] : m_ui8PerformAction[pos];

				//获取优先级
				uint8 ui8UserActionRank = GetUserActionRank(ui8UserAction, pos, ui8TargetPos, m_ui8ProvidePos, ui8CardData);
				uint8 ui8TargetActionRank = GetUserActionRank(ui8TargetAction, ui8TargetPos, pos, m_ui8ProvidePos, ui8CardData);

				//判断并更新最高优先级
				if (ui8UserActionRank > ui8TargetActionRank)
				{
					ui8TargetPos = pos;
					ui8TargetAction = ui8UserAction;
				}
			}
			//			Log.Debug("TWMJAIChannelInterface::UserOperateCard", "1");
			//优先级最高的玩家是否已经操作过
			if (m_bResponse[ui8TargetPos] == false)
			{
				WorldPacket packet;
				if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_Wite))
					SendProtocolToPlayer(&packet, ui8PlayerPosID);
				m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetPos = %d", ui8TargetPos);
				return true;
			}

			bool isEnd = false;

			//等待所有能胡牌的人胡牌

			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				if (m_ChiHuRight[i].IsEmpty() == false && m_bPlayStatus[i] == true)
				{
					isEnd = true;
				}
			}

			m_next_run_status = en_MJChannelState_GiveCard;

			//没有更高优先级的操作并且放弃
			if (ui8TargetAction == WIK_NULL)
			{
				VecInit<uint8>(m_bResponse, m_nMaxPlayerNum, false);
				VecInit<uint8>(m_ui8UserAction, m_nMaxPlayerNum, 0);
				VecInit<uint8>(m_ui8OperateCard, m_nMaxPlayerNum, 0);
				VecInit<uint8>(m_ui8PerformAction, m_nMaxPlayerNum, 0);

				if (m_ui8GangPlayer != INVALID_uint8)
				{
					m_ui8CurrentPos = m_ui8GangPlayer;
					m_ui8SendCardPos = INVALID_uint8;
					m_next_run_status = en_MJChannelState_GiveCard;
					SelfGang(m_ui8GangPlayer, m_ui8GangCard, ui8CardData, false);
					m_ui8GangPlayer = INVALID_uint8;
					return true;
				}
				if (m_ui8AllPlayerOperatorStatus == enAllPlayerOperatorStatus_HaveOperator)
				{
					if (isEnd)
					{
						m_ui8AllPlayerOperatorStatus = enAllPlayerOperatorStatus_AllPlayerOperator;
						BeforeGameOverCalc();
					}
				}
				return true;
			}

			uint8 ui8TargetCard = m_ui8OperateCard[ui8TargetPos];

			m_ui8OutCardData = 0;
			m_bSendStatus = true;
			m_ui8OutCardPos = INVALID_uint8;
			m_bEnjoinChiHu[ui8TargetPos] = false;
			m_vecLouHuCards[ui8TargetPos].clear();

			//胡牌
			uint8 ui8LastHuUser = INVALID_uint8;

			tagWeaveItem WeaveItem;
			WeaveItem.ui8CenterCard = ui8TargetCard;
			WeaveItem.ui8ProvidePos = m_ui8ProvidePos;
			if (ui8TargetAction != WIK_CHI_HU)
			{
				if (ui8TargetAction == WIK_LEFT)
				{
					uint8 ui8Card = m_ui8ProvideCard;
					std::vector<uint8> CardData;
					if (ui8Card - 1 == ui8TargetCard)
					{
						CardData.push_back(ui8TargetCard);
						CardData.push_back(ui8TargetCard + 2);
					}
					else if (ui8Card == ui8TargetCard)
					{
						CardData.push_back(ui8TargetCard + 1);
						CardData.push_back(ui8TargetCard + 2);
					}
					else if (ui8Card - 2 == ui8TargetCard)
					{
						CardData.push_back(ui8TargetCard);
						CardData.push_back(ui8TargetCard + 1);
					}
					m_ui8TargetCardData[ui8TargetPos] = CardData;
					ui8CardData = CardData;
				}
				if (ui8CardData.size())
					RemoveCard(ui8TargetPos, m_ui8TargetCardData[ui8TargetPos]);
				else
					RemoveCardByAction(ui8TargetPos, ui8TargetAction, ui8TargetCard);
				WeaveItem.bHasScore = true;
				WeaveItem.ui8Type = 1;
				WeaveItem.ui8WeaveKind = ui8TargetAction;
				if (WeaveItem.ui8WeaveKind == WIK_LEFT)
				{
					WeaveItem.ui8CardData[0] = WeaveItem.ui8CenterCard;
					WeaveItem.ui8CardData[1] = WeaveItem.ui8CenterCard + 1;
					WeaveItem.ui8CardData[2] = WeaveItem.ui8CenterCard + 2;
				}
				else if (WeaveItem.ui8WeaveKind == WIK_PENG)
				{
					WeaveItem.ui8CardData[0] = WeaveItem.ui8CenterCard;
					WeaveItem.ui8CardData[1] = WeaveItem.ui8CenterCard;
					WeaveItem.ui8CardData[2] = WeaveItem.ui8CenterCard;
				}
				else if (WeaveItem.ui8WeaveKind == WIK_GANG)
				{
					WeaveItem.ui8CardData[0] = WeaveItem.ui8CenterCard;
					WeaveItem.ui8CardData[1] = WeaveItem.ui8CenterCard;
					WeaveItem.ui8CardData[2] = WeaveItem.ui8CenterCard;
					WeaveItem.ui8CardData[3] = WeaveItem.ui8CenterCard;
				}
			}

			MJBaseTablePlayer *pTp = GetTablePlayerByPos(ui8PlayerPosID);

			if (m_WeaveItemArray[ui8TargetPos].size() > MAX_WEAVE)
			{
				Log.Error("TWMJAIChannelInterface::UserOperateCard", "m_ui8WeaveItemCount[%d] :%d", ui8TargetPos, m_WeaveItemArray[ui8TargetPos].size());
				ASSERT(0);
			}
			if (ui8TargetAction == WIK_LEFT)
			{
				m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetPos = %d WIK_LEFT", ui8TargetPos);
				OperateChi(ui8TargetPos, WeaveItem);
				m_WeaveItemArray[ui8TargetPos].push_back(WeaveItem);
			}
			else if (ui8TargetAction == WIK_PENG)
			{
				m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetPos = %d WIK_PENG", ui8TargetPos);
				OperatePeng(ui8TargetPos, WeaveItem);

				m_WeaveItemArray[ui8TargetPos].push_back(WeaveItem);
			}
			else if (ui8TargetAction == WIK_GANG)
			{
				m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetPos = %d WIK_GANG", ui8TargetPos);
				OperateGang(ui8TargetPos, WeaveItem);
				m_bGangStatus = true;
				m_bGangOutStatus = true;
				m_bGangKai = true;
				m_WeaveItemArray[ui8TargetPos].push_back(WeaveItem);

				WorldPacket packet;
				/*if (sProtocolsMgr.CreateOperatePengGangPacket(&packet, ui8TargetPos, m_WeaveItemArray[ui8TargetPos][ui8Index]))
					BroadcastPacket(&packet);*/
				//回放记录
				PlayBack(&packet);
				pTp->mingGangNum++;
			}
			else if (ui8TargetAction == WIK_CHI_HU)
			{
				OperateHu(ui8TargetPos, m_ui8ProvidePos, ui8TargetCard);
				m_ui8ChiHuCard = ui8TargetCard;
				//胡牌判断

				m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetPos = %d  ui8TargetCard:%d WIK_CHI_HU", ui8TargetPos, ui8TargetCard);
				m_ui32ChiHuKind[ui8TargetPos] = AnalyseHuCard(ui8TargetPos, m_ui8UserCardIndex[ui8TargetPos],
															  m_WeaveItemArray[ui8TargetPos],
															  ui8TargetCard,
															  m_ChiHuRight[ui8TargetPos]);
				if (ui8TargetCard)
					m_ui8UserCardIndex[ui8TargetPos][m_GameLogic->SwitchToCardIndex(ui8TargetCard)]++;

				if (m_ui32ChiHuKind[ui8TargetPos] != WIK_NULL)
				{
					m_ui8YiPaoDuoXiangList[ui8TargetPos] = 1;
				}
				if (m_bGangOutStatus)
				{
				}
				if (m_bGangStatus)
				{
					m_ui8QiangGangProvidePos = m_ui8ProvidePos;
					m_ui8QiangGangProvideCard = m_ui8ChiHuCard;
					/*	next_run_status = en_ChannelRun_CalcWait;
					return  true;*/
				}
				m_bPlayStatus[ui8TargetPos] = false;
				if (m_nGameModeFlag == enMJGameMode_SCMJ_XLCH)
				{
					m_bPlayStatus[ui8TargetPos] = true;
				}
			}
			for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
			{
				if (m_ChiHuRight[i].IsEmpty() == false && m_bPlayStatus[i] == true)
				{
					Log.Debug("TWMJAIChannelInterface::UserOperateCard", "m_bPlayStatus[%d]:%d", i, m_bPlayStatus[i]);
					isEnd = true;
				}
			}
			if (m_GameLogic->AllowedYiPaoDuoXiang())
			{ //一炮多响
				if (IsEstimateYiPaoDuoXiang() && m_GameLogic->IsYiPaoDuoXiangOperate(ui8TargetAction))
				{

					for (uint8 i = 0; i < m_nMaxPlayerNum; i++)
					{
						bool isOp = m_GameLogic->IsYiPaoDuoXiangOperate(m_ui8UserAction[i]);
						m_GameLogic->LogDeBug("YiPaoDuoXiang", "i:%d  isOp:%d m_bResponse[i]:%d m_ui8UserAction[i]:%d", i, isOp, m_bResponse[i], m_ui8UserAction[i]);
						if (m_bResponse[i] == false && isOp)
						{
							m_ui8AllPlayerOperatorStatus = enAllPlayerOperatorStatus_HaveOperator;
							break;
						}
						else if ((m_bResponse[i] == true && (i == m_nMaxPlayerNum - 1)) || (isOp == false && (i == m_nMaxPlayerNum - 1)))
						{
							m_ui8AllPlayerOperatorStatus = enAllPlayerOperatorStatus_AllPlayerOperator;
							isEnd = true;
						}
					}
					//一炮多响 判断所有能胡的都胡了就结束
					if (m_ui8AllPlayerOperatorStatus == enAllPlayerOperatorStatus_AllPlayerOperator)
					{
						if (isEnd)
							BeforeGameOverCalc();
					}
					else if (m_ui8AllPlayerOperatorStatus == enAllPlayerOperatorStatus_HaveOperator)
					{
						return true;
					}
					return true;
				}
				else
				{
					if (ui8TargetAction == WIK_CHI_HU)
					{
						m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetPos = %d WIK_CHI_HU END", ui8TargetPos);
						WorldPacket packet;
						if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_OK))
							SendProtocolToPlayer(&packet, ui8PlayerPosID);
						BeforeGameOverCalc();
						return true;
					}
				}
			}
			else
			{
				if (ui8TargetAction == WIK_CHI_HU)
				{
					m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetPos = %d WIK_CHI_HU END", ui8TargetPos);
					WorldPacket packet;
					if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_OK))
						SendProtocolToPlayer(&packet, ui8PlayerPosID);
					BeforeGameOverCalc();
					return true;
				}
			}
			m_GameLogic->LogDeBug("TWMJAIChannelInterface::UserOperateCard", " ui8TargetAction = %d ", ui8TargetAction);
			VecInit<uint8>(m_bResponse, m_nMaxPlayerNum, false);
			VecInit<uint8>(m_ui8UserAction, m_nMaxPlayerNum, 0);
			VecInit<uint8>(m_ui8OperateCard, m_nMaxPlayerNum, 0);
			VecInit<uint8>(m_ui8PerformAction, m_nMaxPlayerNum, 0);
			std::vector<uint8> m_ui8TargetCardDataTemp;
			VecInit<std::vector<uint8> >(m_ui8TargetCardData, m_nMaxPlayerNum, m_ui8TargetCardDataTemp);

			WorldPacket packet;
			if (ui8TargetAction != WIK_CHI_HU && ui8TargetAction != WIK_NULL)
			{
				if (sProtocolsMgr.CreateMJOperatePengGangPacket(&packet, ui8TargetPos, WeaveItem, m_ui8ProvideCard))
					BroadcastPacket(&packet);
				PlayBack(&packet);
			}

			//	回放记录
			if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_OK))
				SendProtocolToPlayer(&packet, ui8PlayerPosID);
			m_ui8CurrentPos = ui8TargetPos;

			if (isEnd)
				BeforeGameOverCalc();
			if (ui8TargetAction == WIK_LEFT)
			{
				/*if (sProtocolsMgr.CreateMJCastCardNotify(&packet, ui8PlayerPosID, m_nCastHandCardTime))
					BroadcastPacket(&packet, ui8PlayerPosID);


				setStatusEndTimer(m_nAGiveHandCardTime);*/

				m_next_run_status = en_MJChannelState_CastCard;
			}
			else if (ui8TargetAction == WIK_PENG)
			{
				/*	if (sProtocolsMgr.CreateMJCastCardNotify(&packet, ui8PlayerPosID, m_nCastHandCardTime))
						BroadcastPacket(&packet, ui8PlayerPosID);
					setStatusEndTimer(m_nAGiveHandCardTime);*/
				//听牌

				m_next_run_status = en_MJChannelState_CastCard;
			}
			else if (ui8TargetAction == WIK_GANG)
			{
				m_next_run_status = en_MJChannelState_GiveCard;
			}
			return true;
		}
		else if (m_ui8CurrentPos == ui8PlayerPosID)
		{ //玩家摸牌后提供的操作

			//无操作或操作无效
			if ((m_ui8UserAction[ui8PlayerPosID] & ui8OperateCode) == 0 && ui8OperateCode != 0)
			{
				/*WorldPacket	packet;
				if (sProtocolsMgr.CreateOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_Error))
					SendProtocolToChaidId(ui8PlayerPosID, &packet);*/
				return false;
			}
			if (m_GameLogic->IsValidCard(ui8OperateCard) == false && ui8OperateCode != 0)
			{
				Log.Error("TWMJAIChannelInterface::UserOperateCard", "ui8OperateCard error :%d ui8PlayerPosID:%d ui8OperateCode:%d", ui8OperateCard, ui8PlayerPosID, ui8OperateCode);
				//ASSERT(0);
				//return false;
			}
			m_bAnyOperate = true;
			m_bSendStatus = true;
			m_bEnjoinChiHu[m_ui8CurrentPos] = false;
			m_vecLouHuCards[m_ui8CurrentPos].clear();

			m_ui8UserAction[m_ui8CurrentPos] = WIK_NULL;
			m_ui8PerformAction[m_ui8CurrentPos] = WIK_NULL;

			bool bPublic = true;
			if(ui8OperateCode != WIK_NULL && m_nQiQiangYiPos != 255)
			{
				m_ui8UserAction[m_nQiQiangYiPos] = WIK_NULL;
			}
			switch (ui8OperateCode)
			{
			case WIK_GANG:
			{
				m_bGangKai = true;
				m_ui8CurrentPos = ui8PlayerPosID;
				m_ui8SendCardPos = INVALID_uint8;
				SelfGang(ui8PlayerPosID, ui8OperateCard, ui8CardData, m_bQiangGangHu);
				break;
			}
			case WIK_CHI_HU:
			{
				OperateHu(ui8PlayerPosID, ui8PlayerPosID, m_uint8SendCardData);
				m_ui8ProvidePos = m_ui8CurrentPos;

				m_ui8ProvideCard = m_uint8SendCardData;

				m_GameLogic->RemoveCard(m_ui8UserCardIndex[ui8PlayerPosID], m_ui8ProvideCard);
				m_ui32ChiHuKind[ui8PlayerPosID] = AnalyseHuCard(ui8PlayerPosID, m_ui8UserCardIndex[ui8PlayerPosID],
																m_WeaveItemArray[ui8PlayerPosID],
																m_ui8ProvideCard,
																m_ChiHuRight[ui8PlayerPosID]);

				m_ui8ChiHuCard = m_ui8ProvideCard;

				m_ui8UserCardIndex[ui8PlayerPosID][m_GameLogic->SwitchToCardIndex(m_ui8ProvideCard)]++;
				m_bPlayStatus[ui8PlayerPosID] = false;
				if (m_nGameModeFlag == enMJGameMode_SCMJ_XLCH)
				{
					m_bPlayStatus[ui8PlayerPosID] = true;
				}
				BeforeGameOverCalc();
				break;
			}
			case WIK_LISTEN:
			{
				m_bBaoJiao[m_ui8CurrentPos] = true;
				OperateListen(ui8PlayerPosID, ui8OperateCard);
				std::vector<uint8> mTemp;
				mTemp = m_MPlayerTingCardList[ui8PlayerPosID][ui8OperateCard];
				m_MPlayerTingCardList[ui8PlayerPosID].clear();
				m_MPlayerTingCardList[ui8PlayerPosID][ui8OperateCard] = mTemp;

				WorldPacket packet;
				if (sProtocolsMgr.CreateMJOperateListenPacket(&packet, ui8PlayerPosID))
					BroadcastPacket(&packet);

				UserOutCard(ui8PlayerPosID, ui8OperateCard);
				break;
			}
			case WIK_NULL:
				{
					Log.Notice("TWMJAIChannelInterface::UserOperateCard", "m_nQiQiangYiPos[%d] m_ui8CurrentPos[%d]", m_nQiQiangYiPos, m_ui8CurrentPos);
					if (m_nQiQiangYiPos != 255 && m_ui8UserAction[m_nQiQiangYiPos] == WIK_NULL)
						m_next_run_status = en_MJChannelState_CastCard;
					else if(m_nQiQiangYiPos == 255)
						m_next_run_status = en_MJChannelState_CastCard;

					Log.Notice("TWMJAIChannelInterface::UserOperateCard", "m_nQiQiangYiPos[%d] m_ui8CurrentPos[%d] m_next_run_status[%d]", m_nQiQiangYiPos, m_ui8CurrentPos, m_next_run_status);
				}
			}
		}
		WorldPacket packet;
		if (sProtocolsMgr.CreateMJOperatePacket(&packet, ui8OperateCode, ui8OperateCard, enUserOperate_OK))
			SendProtocolToPlayer(&packet, ui8PlayerPosID);
		return false;
	}

}


